Page 2 of 3

Posted: Sun Apr 18, 2004 6:24 pm
by mikewooten
ok.. i used your example and this is what the output is and what it displayed.

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

how do you fix it?
thanks

Posted: Sun Apr 18, 2004 6:33 pm
by redmonkey
Insert a line right before...

Code: Select all

$result=mysql_query($query) or die ('ERROR : '. mysql_error());
and put....

Code: Select all

echo $query;
And let me know what the output is.

Posted: Sun Apr 18, 2004 6:42 pm
by mikewooten
the output displays

SELECT * FROM `checkout` WHERE `id` = 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

??

Posted: Sun Apr 18, 2004 6:51 pm
by redmonkey
That suggest to me that you have not set the variable for the mysql_insert_id properly.

Posted: Sun Apr 18, 2004 7:02 pm
by mikewooten
how do i set the mysql_insert_id?
i have used the example that is given on their site which is:

printf("Last inserted record has id %d\n", mysql_insert_id());
is that what i should be using or not, if not what should i use to set mysql_insert_id

Posted: Sun Apr 18, 2004 7:20 pm
by redmonkey
Try...

Code: Select all

$insert_id_variable = mysql_insert_id();

Posted: Sun Apr 18, 2004 7:40 pm
by mikewooten
ok..ive set the variable and it gives me this message displayed on the page

SELECT * FROM `checkout` WHERE `id` = 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

??

Posted: Sun Apr 18, 2004 7:46 pm
by redmonkey
Post the entire code you are working with right now. We could go on like this forever. That error is the same as the previous one which leads me to think that have not set the variable correctly.

Posted: Sun Apr 18, 2004 8:13 pm
by mikewooten
here's the code:

Code: Select all

<?php



session_start();

       // include function files for this application
require_once('bookmark_fns.php'); 


//create short variable names
$username = $HTTP_POST_VARS['username'];
$passwd = $HTTP_POST_VARS['passwd'];

if ($username && $passwd)
// they have just tried logging in
{
    if (login($username, $passwd))
    {
      // if they are in the database register the user id
      $HTTP_SESSION_VARS['valid_user'] = $username;
    }  
    else
    {
      // unsuccessful login
      do_html_header('Problem:');
      echo 'You could not be logged in. 
            You must be logged in to view this page.';
      do_html_url('login.php', 'Login');
      do_html_footer();
      exit;
    }      
}


$db_name = "database"; 
$table_name = "checkout"; 

$link_id = mysql_connect("localhost", "username", "password")  
or die("Couldn't connect."); 

$db = mysql_select_db($db_name, $link_id) 
    or die("Couldn't select database."); 

mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty)  
			VALUES  ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')"); 

 
echo "$select<br>";
					
	$host    ="localhost";
	$db_user="username";
	$db_pass="password";
	$database="database";
					
mysql_connect($host,$db_user,$db_pass);
mysql_select_db($database) or die ("Unable to select database");    


echo "<center>Thank You For Shopping With Us!</center><br>"; 
echo "<center>";  
check_valid_user(); 

echo "</center>"; 
echo "<br>";
echo "<center><a href='logout.php'>Click here to Logout</a></center>";
echo "<br>";
include("check.php");
echo "<br>"; 

echo "<strong>Your Billing and Shipping information!</strong>";

$query = "SELECT * FROM `$table_name` WHERE `id` = $id"; 

echo $query; 
$result=mysql_query($query) or die ('ERROR : '. mysql_error()); 

$num=mysql_numrows($result);  
echo "<br><br>";
echo "id variable";
$insert_id_variable = mysql_insert_id(); 

echo "<br>";
echo "the number of rows are:&nbsp;&nbsp;&nbsp;&nbsp;";
echo $num;

if (!function_exists('datecheck')) 
{ 
  
function datecheck($intext) { 
$theresults = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed); 
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; } 
    
echo(""$intext" $isamatch<br>\n"); 
} 

} 


function phonecheck($intext) {
   $theresults = ereg("([0-9]{3})-([0-9]{3})-([0-9]{4})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo(""$intext" $isamatch<br>\n");
} 

function ccnumcheck($intext) {
   $theresults = ereg("([0-9]{16})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo(""$intext" $isamatch<br>\n");
} 

function emailcheck($intext) {
   $theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo(""$intext" $isamatch<br>\n");
} 

$result = mysql_query($query, $link_id);

 
while($query_data = mysql_fetch_row($result)) { 

echo "<table>"; 
 
echo "<tr>";
echo "<td>billfirstname</td>";
echo "<td>",$query_data[0],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>billlastname</td>";
echo "<td>",$query_data[1],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>billstreetaddr</td>";
echo "<td>",$query_data[2],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>billcity</td>";
echo "<td>",$query_data[3],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>billstate</td>";
echo "<td>",$query_data[4],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>billzipcode</td>";
echo "<td>",$query_data[5],"</td>"; 
echo "</tr>"; 

echo "<tr>";
echo "<td>billcountry</td>";
echo "<td>",$query_data[6],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>email<br>"; 
echo "</td>";
echo "<td>",emailcheck("$email"),"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>phone</td>";
echo "<td>",phonecheck("$phone"),"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>payment</td>";
echo "<td>",$query_data[10],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>creditnum</td>";
echo "<td>",ccnumcheck($creditnum),"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>expire</td>";
echo "<td>",datecheck($expire),"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>questions</td>";
echo "<td>",$query_data[13],"</td>";
echo "</tr>";   

echo "<tr>";
echo "<td>shipfirstname</td>";
echo "<td>",$query_data[14],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shiplastname</td>";
echo "<td>",$query_data[15],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>shipstreetaddr</td>";
echo "<td>",$query_data[16],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipcity</td>";
echo "<td>",$query_data[17],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>shipstate</td>";
echo "<td>",$query_data[18],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipzipcode</td>";
echo "<td>",$query_data[19],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipcountry</td>";
echo "<td>",$query_data[20],"</td>";
echo "</tr>"; 

echo "</table>";     
                   
                        if(isset($_COOKIE['cartId']))  { 
                        
                        echo "<center><strong>----- cookie is set ----- </strong></center>";
                        
                        }
                        
                        else {
                        
                        echo "<center><strong>----- cookie is NOT set ----- </strong></center>";
                        
                        }
}




?>

Posted: Sun Apr 18, 2004 9:00 pm
by redmonkey
Find this block of code...

Code: Select all

mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty) 
         VALUES  ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')");
And replace with....

Code: Select all

mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty) 
         VALUES  ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')"); 

$id = mysql_query_id();
Then remove....

Code: Select all

$insert_id_variable = mysql_insert_id();

Posted: Sun Apr 18, 2004 9:07 pm
by mikewooten
it gives me the same error message as before.

SELECT * FROM `checkout` WHERE `id` = 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

??

Posted: Sun Apr 18, 2004 9:13 pm
by redmonkey
Thats probably down to me consuming too much Guiness.

Change....

Code: Select all

$id = mysql_query_id();
to...

Code: Select all

$id = mysql_insert_id();
If that doesn't work then try...

Code: Select all

$id = mysql_insert_id($link_id);

Posted: Sun Apr 18, 2004 9:20 pm
by mikewooten
it still gives me the same error.


??

Posted: Sun Apr 18, 2004 9:32 pm
by redmonkey
Well all I can tell you at present is that $id is obviously not being assigned a value, this generally happens when the insert statement fails.

Have you checked that when you perform an update/insert that the information is going into the database?

Posted: Sun Apr 18, 2004 11:54 pm
by mikewooten
i just checked my database and it seems like the id is being counted every time that i enter information into the form and click submit, but there is no information going into the database.

how else can i get my insert statement to work so that $id can be assigned a value?