Jump to content


Photo

Error in Syntax for Insert [Solved]


  • Please log in to reply
5 replies to this topic

#1 156418

156418
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 13 October 2006 - 11:45 AM

I'm trying to run the following query:

<?php
// sort out the input
$cartId = $_POST['cartId'];
$description = $_POST['desc'];
$totalamount = $_POST['amount'];
$transactioncurrency = $_POST['currency'];
$customername = $_POST['name'];
$customeraddress = $_POST['address'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$transId = $_POST['transId'];
$transStatus = $_POST['transStatus'];
$transTime = $_POST['transTime'];
$authAmount = $_POST['authAmount'];
$authCurrency = $_POST['authCurrency'];
$rawAuthMessage = $_POST['rawAuthMessage'];
$rawAuthCode = $_POST['rawAuthCode'];
$cardType = $_POST['cardType'];
$AVS = $_POST['AVS'];

//1) Now dump the lot into the DB
  $query = "INSERT INTO Callbacks (
             cartId, desc, amount, currency, name, address, postcode, country, tel, email, transId, transStatus, transTime, authAmount, authCurrency, rawAuthMessage, rawAuthCode, cardType, AVS)
             VALUES (
            '$cartId',
            '$description',
            '$totalamount',
            '$transactioncurrency',
            '$customername',
            '$customeraddress',
            '$postcode',
            '$country',
            '$countryString',
            '$tel',
            '$email',
            '$transId',
			'$transStatus',			
			'$transTime',
			'$authAmount',
			'$authCurrency',
			'$rawAuthMessage',
			'$rawAuthCode',
			'$cardType',
            '$AVS')";

	echo $query. "<br/>";
$insert = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query);
?>

When the query runs, the echo is showing that all the data is there to be put in, but I'm getting the error.

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 'desc, amount, currency, name, address, postcode, country, countryString, tel, em' at line 2 with query INSERT INTO Callbacks etc


Knowing my typing, its probably a typo somewhere, but I can't spot it!

Any help greatly received

#2 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 13 October 2006 - 11:50 AM

You're trying to insert both $country (which is defined) and $countryString (which isn't defined) into the database.  You don't seem to have a countrystring column to put it into, so you're overrunning the boundary of your table by trying to insert a record that's one column too large.
Using 'global' is a sign of doing it wrong

#3 156418

156418
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 13 October 2006 - 12:05 PM

Thanks, I've removed that but still got the same error  ???

#4 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 13 October 2006 - 12:12 PM

Even if $countryString wasn't defined, it would be insterted as NUL.

You should really follow the SQL syntax, MySQL can become quiet fussy when it comes to large queries.

$query = "INSERT INTO `Callbacks` (`cartId, `desc`, `amount`, `currency`, `name`, `address`, `postcode`, `country`, `tel`, `email`, `transId`, `transStatus`, `transTime`, `authAmount`, `authCurrency`, `rawAuthMessage`, `rawAuthCode`, `cardType`, `AVS`) VALUES ('$cartId', '$description', '$totalamount', '$transactioncurrency', '$customername', '$customeraddress', '$postcode', '$country', '$countryString', '$tel', '$email', '$transId', '$transStatus', '$transTime', '$authAmount', '$authCurrency', '$rawAuthMessage', '$rawAuthCode', '$cardType', '$AVS')";

*removed Tabs and newlines, send MySQL your query in the nicest way possible :)

#5 mjlogan

mjlogan
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 13 October 2006 - 12:22 PM

desc is a reserved keyword, change the column name.

#6 156418

156418
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 13 October 2006 - 12:40 PM

Hmmm thanks, thats annoying, as thats something that Worldpay spit out as one of their defined colums.

Sorted it now by sending them an additional field which is put into DB. Everything working ok.


Thanks for all the help






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users