156418 Posted October 13, 2006 Share Posted October 13, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/23839-error-in-syntax-for-insert-solved/ Share on other sites More sharing options...
KevinM1 Posted October 13, 2006 Share Posted October 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23839-error-in-syntax-for-insert-solved/#findComment-108268 Share on other sites More sharing options...
156418 Posted October 13, 2006 Author Share Posted October 13, 2006 Thanks, I've removed that but still got the same error ??? Quote Link to comment https://forums.phpfreaks.com/topic/23839-error-in-syntax-for-insert-solved/#findComment-108275 Share on other sites More sharing options...
heckenschutze Posted October 13, 2006 Share Posted October 13, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/23839-error-in-syntax-for-insert-solved/#findComment-108281 Share on other sites More sharing options...
mjlogan Posted October 13, 2006 Share Posted October 13, 2006 [b]desc[/b] is a reserved keyword, change the column name. Quote Link to comment https://forums.phpfreaks.com/topic/23839-error-in-syntax-for-insert-solved/#findComment-108289 Share on other sites More sharing options...
156418 Posted October 13, 2006 Author Share Posted October 13, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/23839-error-in-syntax-for-insert-solved/#findComment-108299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.