bhavin_85 Posted March 12, 2007 Share Posted March 12, 2007 hey guys ive written an if statement to check for inputs from a form the first statement works perfectly and prints the right info but the second is giving me this error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 <? $cust_id=$_POST['cust_id']; $uname=$_POST['uname']; include('../../config.php'); if(empty($custid)){ $sql = "SELECT * FROM customer WHERE cust_id=$cust_id"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo $row['uname']; echo $row['first_name']; } elseif(empty($uname)) { $sql1 = "SELECT * FROM customer WHERE uname=$uname"; $result1 = mysql_query($sql1) or die(mysql_error()); $row1 = mysql_fetch_assoc($result1); echo $row1['first_name']; } ?> thats the code, i dont get where im gonig wrong ??? Link to comment https://forums.phpfreaks.com/topic/42344-solved-if-statement-error/ Share on other sites More sharing options...
obsidian Posted March 12, 2007 Share Posted March 12, 2007 When you're querying the database against a string, you need to have single quotes around your string. So, your second query should read: SELECT * FROM customer WHERE uname = '$uname' Link to comment https://forums.phpfreaks.com/topic/42344-solved-if-statement-error/#findComment-205404 Share on other sites More sharing options...
bhavin_85 Posted March 12, 2007 Author Share Posted March 12, 2007 thats still giving the same error that field compaires an email address that the user inputs from the form to an email address stored in the database as a varchar if that makes any diff Link to comment https://forums.phpfreaks.com/topic/42344-solved-if-statement-error/#findComment-205405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.