Jump to content


Select Statement with HTML Variables

  • Please log in to reply
2 replies to this topic

#1 jt2006

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 07 July 2006 - 02:11 PM

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());

$query = mysql_query("SELECT * FROM '$usertable' WHERE " '$queryterm' "= email");

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

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

#2 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 July 2006 - 02:16 PM

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";


#3 jt2006

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 07 July 2006 - 02:21 PM

That was it.  Worked on it for several hours yesterday.  Must have blocked out logic.

Thanks so much!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users