Jump to content

Error in Syntax for Insert [Solved]


156418

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
Link to comment
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.
Link to comment
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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.