Solved

MySQL Query result

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

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
The 100 points should be awared to Dave Baldwin.
 visionetv
0
 

Author Closing Comment

by:visionetv
Comment Utility
Overlooked echoing result from query to confirm php code functioning properly
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now