Jump to content


This topic is now archived and is closed to further replies.


Select Statement with HTML Variables

Recommended Posts

Thanks for taking the time to help me out.

I'm trying to do what seems to be a simple select statement.  All I want is for someone to enter in their email address and check the database.  If it's there, retrieve that row.

The problem is that I'm getting all confused as to the proper format of the select statement using the form variables.  I've seen .$variable.  '$variable'  and even '%".$variable."%'.

Can someone take a look and help me out?

Here's my code:



mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

[color=purple]$query = mysql_query("SELECT * FROM '$usertable' WHERE " '$queryterm' "= email");[/color]

if (!$query) {
  die("query Failed. " . mysql_error());

While ($row = mysql_fetch_array($result)) {
echo $row['email'];

Share this post

Link to post
Share on other sites
You need to surround strings with single quotes in MySQL. In your example you have the quotes surrounding the wrong items. Try something like this:
$query = "SELECT * FROM $usertable WHERE email = '$queryterm'";
$result = mysql_query($query) or die("There was a problem with the query: $query<br>" . mysql_error());
while ($row = mysql_fetch_assoc($result))
    echo $row['email'] . "<br>\n";


Share this post

Link to post
Share on other sites
That was it.  Worked on it for several hours yesterday.  Must have blocked out logic.

Thanks so much!

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.