Solved

MySQL Query result

Posted on 2012-03-30
4
275 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
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.

776 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