Jump to content

php MYSQL error


dt_gry

Recommended Posts

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

;D

Link to comment
https://forums.phpfreaks.com/topic/132991-php-mysql-error/
Share on other sites

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

Archived

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

×
×
  • Create New...

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.