scotch33 Posted November 8, 2006 Share Posted November 8, 2006 Hi there,I am writing my first sql app - when a visitor reaches a 'payment completed' page after a payment I am trying to write the transaction details to an orders database.so far, I have created a test database, added a few entries and managed to link to them and display them - si I know the connection is working. However when I try to write a new entry with the code below (basically - calling cookies set before the customer reroutes to the payment gateway), fails to write. I have compared this code with the tutorial I am using to learn from, but can't see anything. can anyone help? Thanks![code]<? $cust_name = $_COOKIE[name]; $cust_surname = $_COOKIE[surname]; $cust_address1 = $_COOKIE[address1]; $cust_address2 = $_COOKIE[address2]; $cust_town = $_COOKIE[town]; $cust_county = $_COOKIE[county]; $cust_postcode = $_COOKIE[postcode]; $cust_email = $_COOKIE[email]; $cust_phone = $_COOKIE[phone]; $unit_quantity = $_COOKIE[amount]; $sql_insert = "INSERT INTO dvd_orders SET cust_name='$cust_name', cust_surname='$cust_surname', cust_address1='$cust_address1', cust_address2='$cust_address2', cust_town='$cust_town', cust_county='$cust_county', cust_postcode='$cust_postcode', cust_email='$cust_email', cust_phone='$cust_phone', unit_quantity='$unit_quantity', unit_cost='30', "; if (@mysql_query($sql_insert)) { echo "this has worked"; } else { echo "this hasn't worked - bugger"; } ?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2006 Share Posted November 8, 2006 It could be any number of things but suppressing errors (@) doesn't help. You need them on while developing. Try...[code=php:0]if (mysql_query($sql_insert)) { echo "this has worked";} else { echo mysql_error();}[/code] Quote Link to comment Share on other sites More sharing options...
r-it Posted November 8, 2006 Share Posted November 8, 2006 this is how i would do it:[color=blue]$sql_insert = "INSERT INTO dvd_orders SET cust_name='".$cust_name."', cust_surname='".$cust_surname."', cust_address1='".$cust_address1."', cust_address2='".$cust_address2."', cust_town='".$cust_town."', cust_county='".$cust_county."', cust_postcode='".$cust_postcode."', cust_email='".$cust_email."', cust_phone='".$cust_phone."', unit_quantity='".$unit_quantity."', unit_cost='".30."',[/color]i think that shud do it if the problem is in the sql query, otherwise its your data from cookies Quote Link to comment Share on other sites More sharing options...
scotch33 Posted November 8, 2006 Author Share Posted November 8, 2006 Thanks thorpe - I have made that change and am now getting the following - You have an error in your SQL syntax near '' at line 13I am about to see if r-it's code does the trick (thanks!) - but I have looked at the php page and line 13 is as follows - <meta name="Author" content="Pearson Treehouse(c) 2006" />not even anywhere near the database! willget back once i have tried alternative code. Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2006 Share Posted November 8, 2006 [quote]but I have looked at the php page and line 13 is as follows -[/quote]No. But, line 12 of your sql statement ends with a , when it shouldn't. Change your sql to...[code=php:0]$sql_insert = "INSERT INTO dvd_orders SET cust_name='$cust_name', cust_surname='$cust_surname', cust_address1='$cust_address1', cust_address2='$cust_address2', cust_town='$cust_town', cust_county='$cust_county', cust_postcode='$cust_postcode', cust_email='$cust_email', cust_phone='$cust_phone', unit_quantity='$unit_quantity', unit_cost='30' ";[/code]PS; r-it's code is no different to yours. And in fact introduces another error. Quote Link to comment Share on other sites More sharing options...
scotch33 Posted November 8, 2006 Author Share Posted November 8, 2006 yep - thats got it - it was the extra ',' - thanks guys! Quote Link to comment Share on other sites More sharing options...
r-it Posted November 8, 2006 Share Posted November 8, 2006 yeah thorpe is rite, it's surely the comma, how ddnt i notice tht, but whenever i get an error, i was just told to do it with '".$something."', so i thot this was the case. Quote Link to comment 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.