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] Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/ 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] Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/#findComment-121491 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 Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/#findComment-121493 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. Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/#findComment-121496 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. Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/#findComment-121497 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! Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/#findComment-121500 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. Link to comment https://forums.phpfreaks.com/topic/26561-resolved-my-first-attempt-to-write-to-a-database-entires-not-writing-help/#findComment-121501 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.