Jump to content

Archived

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

156418

Error in Syntax for Insert [Solved]

Recommended Posts

I'm trying to run the following query:

[code]<?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);
?> [/code]

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

[quote]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[/quote]

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

Any help greatly received

Share this post


Link to post
Share on other sites
You're trying to insert both $country (which is defined) and [b]$countryString[/b] (which [b]isn't[/b] 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.

Share this post


Link to post
Share on other sites
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.

[code]$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')";[/code]

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.