Solved

MySQL Query result

Posted on 2012-03-30
4
279 Views
Last Modified: 2012-04-04
Hello Experts;

I have a MySQL query to echo a result from a single cell in a column named 'status' based on an email address in column 'email'. The email variable is passed from a previous page but the query does not return the cell value in the 'status' column defined by the email address; the code snippet is;

<?php
session_start();
include_once("config.php");
$email=$_SESSION["email"];

mysql_select_db("$dbname", $link) || die("Couldn't open db: $dbname. Error if any was: ".mysql_error() );
$result = mysql_query("SELECT status FROM users WHERE email='$email'");
$row = mysql_fetch_array($result);

$status = $row["status"];

echo $dbname; //test database connect
echo $email; //check variable was passed
mysql_close($link);
?>

Can someone identify what I'm doing wrong and help in correcting the code to return the cell value in the 'status' column  based on the email address variable?

Thank you,
visionetv
0
Comment
Question by:visionetv
  • 3
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37788550
The code looks ok assuming you haven't misspelled anything.  Are you getting an error message or anything?  I don't see that you are echoing $status so you can check it.
0
 

Accepted Solution

by:
visionetv earned 0 total points
ID: 37788998
Dave;

Thanks for pointing out a silly mistake... tough to know the code is working when I didn't echo the result.

Thank,
visoinetv
0
 

Author Comment

by:visionetv
ID: 37789040
The 100 points should be awared to Dave Baldwin.
 visionetv
0
 

Author Closing Comment

by:visionetv
ID: 37805196
Overlooked echoing result from query to confirm php code functioning properly
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question