jt2006 Posted July 7, 2006 Share Posted July 7, 2006 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:$queryterm=$_POST['updateterm'];$hostname="server";$username="DBuser";$password="DBPassword";$dbname="DBName";$usertable="TableName"; 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'];} Quote Link to comment https://forums.phpfreaks.com/topic/13953-select-statement-with-html-variables/ Share on other sites More sharing options...
kenrbnsn Posted July 7, 2006 Share Posted July 7, 2006 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:[code]<?php$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";?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/13953-select-statement-with-html-variables/#findComment-54393 Share on other sites More sharing options...
jt2006 Posted July 7, 2006 Author Share Posted July 7, 2006 That was it. Worked on it for several hours yesterday. Must have blocked out logic.Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/13953-select-statement-with-html-variables/#findComment-54395 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.