dt_gry Posted November 16, 2008 Share Posted November 16, 2008 Hi everyone, I get 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 'primary WHERE (CustID) = '1121600984'' at line 1. when I am running this code, I have pored over this for about an hour and still cannot find where my syntax error is at. <?php include('config.php'); $Con = mysql_connect($Host, $Usr, $Pass); mysql_select_db("$DB", $Con); $PrefUsr = Usr; $Chk = "SELECT * FROM login WHERE Usr = '$PrefUsr'"; $Result = mysql_query($Chk) or die(mysql_error()); If (mysql_num_rows($Result)) { die("The Username that you entered is already in our system! Please try another."); } Else $CustID = rand(1, 9999999999); $MemStat = JJ; $testID = "SELECT * FROM primary WHERE (CustID) = '$CustID'"; $IDresult = mysql_query($testID) or die(mysql_error()); ; If (mysql_num_rows($IDresult)) { die("That Customer ID Already Exhists."); } Else $primary_insert = "INSERT INTO primary(CustID) VALUES('$_POST[$CustID]')"; $login_insert = "INSERT INTO login(CustID, Usr, Pass, MemStat, Email) VALUES('$_POST[$CustID]', '_$Post[usr]', '$_Post[Pass]', $_POST[$MemStat], '$_Post[Email])"; $basic_insert = "INSERT INTO basic(CustID, Fname, Lname, Ctry, St, City, Zip, CCAcct) Values('$_POST[$CustID]', '$_POST[Fname]', '$_POST[Lname]', '$_POST[Ctry]', '$_POST[st]', '$_POST[City]', '$_POST[Zip], '$_POST[CCAcct])"; If (mysql_query($primary_insert)) { die('Error: ' . mysql_error()); } echo "<br />Primary Key Generated and Inserted Successfuly<br />"; If (mysql_query($login_insert)) { die('Error: ' . mysql_error()); } echo "<br />Login Information Collected and Inserted Successfuly<br />"; If (mysql_query($basic_insert)) { die('Error: ' . mysql_error()); } echo "<br />Basic Information Collected and Inserted Successfuly<br />"; mysql_close($Con); ?> Thanks Link to comment https://forums.phpfreaks.com/topic/132991-php-mysql-error/ Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 Change this: $testID = "SELECT * FROM primary WHERE (CustID) = '$CustID'"; to this: $testID = "SELECT * FROM primary WHERE CustID = '$CustID'"; Link to comment https://forums.phpfreaks.com/topic/132991-php-mysql-error/#findComment-691649 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 I would also change this: $primary_insert = "INSERT INTO primary(CustID) VALUES('$_POST[$CustID]')"; to this: $primary_insert = "INSERT INTO primary SET CustID = $_POST[$CustID]"; But I'm not sure what you mean by $_POST[$CustID] Link to comment https://forums.phpfreaks.com/topic/132991-php-mysql-error/#findComment-691651 Share on other sites More sharing options...
Twister1004 Posted November 16, 2008 Share Posted November 16, 2008 Else $CustID = rand(1, 9999999999); $MemStat = JJ; // This is not formed right. //your code : $testID = "SELECT * FROM primary WHERE (CustID) = '$CustID'"; // Correct way : $testID = mysql_query("SELECT * FROM `primary` WHERE [column name] = '$CrustID'"; $testID = mysql_query("SELECT * FROM `primary` WHERE [column name] = '$CrustID'"; $IDresult = mysql_query($testID) or die(mysql_error()); ; If (mysql_num_rows($IDresult)) { die("That Customer ID Already Exhists."); } You didn't define what you wanted to do with that query. Link to comment https://forums.phpfreaks.com/topic/132991-php-mysql-error/#findComment-691653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.