Russia Posted September 26, 2009 Share Posted September 26, 2009 I currently have this php script that adds information to a database from a HUGE form! Code: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $date2 = date("F j Y"); $ip = $_SERVER['REMOTE_ADDR']; require("../inc/config.php"); $sql="INSERT INTO mod ( Username, Password, Recov1, Recov2, Recov3, Recov4, TransactionID, AgreementID, CreditCardSubscriptionMonth, CreditCardSubscriptionYear, TeleBillingPin, PayByCashMonth, PayByCashYear, PayByCashLength, FirstPassword, ThirdPassword, PostCode, Email, BankPin, BankPinConfirm, AccountCreationMonth, AccountCreationYear, Isp, MovedMonth, MovedYear, Message, Ip, AddedDate ) VALUES( '$_POST[username]', '$_POST[password]', '$_POST[recovery1]', '$_POST[recovery2]', '$_POST[recovery3]', '$_POST[recovery4]', '$_POST[transactionid]', '$_POST[futurepayid]', '$_POST[earliestccmonth]', '$_POST[earliestccyear]', '$_POST[username]', '$_POST[telebillingpin]', '$_POST[earliestpbcmonth]', '$_POST[earliestpbcyear]', '$_POST[pbclength]', '$_POST[password1]', '$_POST[password3]', '$_POST[postcode]', '$_POST[email]', '$_POST[newpassword1]', '$_POST[newpassword2]', '$_POST[creationmonth]', '$_POST[isp]', '$_POST[movedmonth]', '$_POST[movedyear]', '$_POST[othercomments]', '$ip', '$date2' )"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close() ?> It is giving my this error: 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 'mod ( Username, Password, Recov1, Recov2, Recov3, Recov4, TransactionID, ' at line 1 And these Notice Messages: Notice: Undefined index: username in /home/brickz/public_html/mod/index5.php on line 43 Notice: Undefined index: password in /home/brickz/public_html/mod/index5.php on line 44 Notice: Undefined index: recovery1 in /home/brickz/public_html/mod/index5.php on line 45 Notice: Undefined index: recovery2 in /home/brickz/public_html/mod/index5.php on line 46 Notice: Undefined index: recovery3 in /home/brickz/public_html/mod/index5.php on line 47 Notice: Undefined index: recovery4 in /home/brickz/public_html/mod/index5.php on line 48 Notice: Undefined index: transactionid in /home/brickz/public_html/mod/index5.php on line 49 Notice: Undefined index: futurepayid in /home/brickz/public_html/mod/index5.php on line 50 Notice: Undefined index: earliestccmonth in /home/brickz/public_html/mod/index5.php on line 51 Notice: Undefined index: earliestccyear in /home/brickz/public_html/mod/index5.php on line 52 Notice: Undefined index: username in /home/brickz/public_html/mod/index5.php on line 53 Notice: Undefined index: telebillingpin in /home/brickz/public_html/mod/index5.php on line 54 Notice: Undefined index: earliestpbcmonth in /home/brickz/public_html/mod/index5.php on line 55 Notice: Undefined index: earliestpbcyear in /home/brickz/public_html/mod/index5.php on line 56 Notice: Undefined index: pbclength in /home/brickz/public_html/mod/index5.php on line 57 Notice: Undefined index: password1 in /home/brickz/public_html/mod/index5.php on line 58 Notice: Undefined index: password3 in /home/brickz/public_html/mod/index5.php on line 59 Notice: Undefined index: postcode in /home/brickz/public_html/mod/index5.php on line 60 Notice: Undefined index: email in /home/brickz/public_html/mod/index5.php on line 61 Notice: Undefined index: newpassword1 in /home/brickz/public_html/mod/index5.php on line 62 Notice: Undefined index: newpassword2 in /home/brickz/public_html/mod/index5.php on line 63 Notice: Undefined index: creationmonth in /home/brickz/public_html/mod/index5.php on line 64 Notice: Undefined index: isp in /home/brickz/public_html/mod/index5.php on line 65 Notice: Undefined index: movedmonth in /home/brickz/public_html/mod/index5.php on line 66 Notice: Undefined index: movedyear in /home/brickz/public_html/mod/index5.php on line 67 Notice: Undefined index: othercomments in /home/brickz/public_html/mod/index5.php on line 68 What is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/ Share on other sites More sharing options...
mikesta707 Posted September 26, 2009 Share Posted September 26, 2009 for arrays you either have to do this '".$_POST['earliestccyear']."', //or this '{$_POST['earliestccyear']}', Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925120 Share on other sites More sharing options...
Russia Posted September 26, 2009 Author Share Posted September 26, 2009 So what one is the correct way of doing it? Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925121 Share on other sites More sharing options...
Russia Posted September 26, 2009 Author Share Posted September 26, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925125 Share on other sites More sharing options...
Alex Posted September 26, 2009 Share Posted September 26, 2009 Just replace like '$_POST[username]', with '{$_POST[username]}', Do that for all of the arrays. Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925126 Share on other sites More sharing options...
Russia Posted September 26, 2009 Author Share Posted September 26, 2009 Still doesnt work. Here is updated code: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $date2 = date("F j Y"); $ip = $_SERVER['REMOTE_ADDR']; require("../inc/config.php"); $sql="INSERT INTO mod ( Username, Password, Recov1, Recov2, Recov3, Recov4, TransactionID, AgreementID, CreditCardSubscriptionMonth, CreditCardSubscriptionYear, TeleBillingPin, PayByCashMonth, PayByCashYear, PayByCashLength, FirstPassword, ThirdPassword, PostCode, Email, BankPin, BankPinConfirm, AccountCreationMonth, AccountCreationYear, Isp, MovedMonth, MovedYear, Message, Ip, AddedDate ) VALUES ( '{$_POST[username]}', '{$_POST[password]}', '{$_POST[recovery1]}', '{$_POST[recovery2]}', '{$_POST[recovery3]}', '{$_POST[recovery4]}', '{$_POST[transactionid]}', '{$_POST[futurepayid]}', '{$_POST[earliestccmonth]}', '{$_POST[earliestccyear]}', '{$_POST[username]}', '{$_POST[telebillingpin]}', '{$_POST[earliestpbcmonth]}', '{$_POST[earliestpbcyear]}', '{$_POST[pbclength]}', '{$_POST[password1]}', '{$_POST[password3]}', '{$_POST[postcode]}', '{$_POST[email]}', '{$_POST[newpassword1]}', '{$_POST[newpassword2]}', '{$_POST[creationmonth]}', '{$_POST[isp]}', '{$_POST[movedmonth]}', '{$_POST[movedyear]}', '{$_POST[othercomments]}', '$ip', '$date2' )"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close() ?> Now these are the errors: Notice: Use of undefined constant username - assumed 'username' in /home/brickz/public_html/mod/index5.php on line 44 Notice: Undefined index: username in /home/brickz/public_html/mod/index5.php on line 44 Notice: Use of undefined constant password - assumed 'password' in /home/brickz/public_html/mod/index5.php on line 45 Notice: Undefined index: password in /home/brickz/public_html/mod/index5.php on line 45 Notice: Use of undefined constant recovery1 - assumed 'recovery1' in /home/brickz/public_html/mod/index5.php on line 46 Notice: Undefined index: recovery1 in /home/brickz/public_html/mod/index5.php on line 46 Notice: Use of undefined constant recovery2 - assumed 'recovery2' in /home/brickz/public_html/mod/index5.php on line 47 Notice: Undefined index: recovery2 in /home/brickz/public_html/mod/index5.php on line 47 Notice: Use of undefined constant recovery3 - assumed 'recovery3' in /home/brickz/public_html/mod/index5.php on line 48 Notice: Undefined index: recovery3 in /home/brickz/public_html/mod/index5.php on line 48 Notice: Use of undefined constant recovery4 - assumed 'recovery4' in /home/brickz/public_html/mod/index5.php on line 49 Notice: Undefined index: recovery4 in /home/brickz/public_html/mod/index5.php on line 49 Notice: Use of undefined constant transactionid - assumed 'transactionid' in /home/brickz/public_html/mod/index5.php on line 50 Notice: Undefined index: transactionid in /home/brickz/public_html/mod/index5.php on line 50 Notice: Use of undefined constant futurepayid - assumed 'futurepayid' in /home/brickz/public_html/mod/index5.php on line 51 Notice: Undefined index: futurepayid in /home/brickz/public_html/mod/index5.php on line 51 Notice: Use of undefined constant earliestccmonth - assumed 'earliestccmonth' in /home/brickz/public_html/mod/index5.php on line 52 Notice: Undefined index: earliestccmonth in /home/brickz/public_html/mod/index5.php on line 52 Notice: Use of undefined constant earliestccyear - assumed 'earliestccyear' in /home/brickz/public_html/mod/index5.php on line 53 Notice: Undefined index: earliestccyear in /home/brickz/public_html/mod/index5.php on line 53 Notice: Use of undefined constant username - assumed 'username' in /home/brickz/public_html/mod/index5.php on line 54 Notice: Undefined index: username in /home/brickz/public_html/mod/index5.php on line 54 Notice: Use of undefined constant telebillingpin - assumed 'telebillingpin' in /home/brickz/public_html/mod/index5.php on line 55 Notice: Undefined index: telebillingpin in /home/brickz/public_html/mod/index5.php on line 55 Notice: Use of undefined constant earliestpbcmonth - assumed 'earliestpbcmonth' in /home/brickz/public_html/mod/index5.php on line 56 Notice: Undefined index: earliestpbcmonth in /home/brickz/public_html/mod/index5.php on line 56 Notice: Use of undefined constant earliestpbcyear - assumed 'earliestpbcyear' in /home/brickz/public_html/mod/index5.php on line 57 Notice: Undefined index: earliestpbcyear in /home/brickz/public_html/mod/index5.php on line 57 Notice: Use of undefined constant pbclength - assumed 'pbclength' in /home/brickz/public_html/mod/index5.php on line 58 Notice: Undefined index: pbclength in /home/brickz/public_html/mod/index5.php on line 58 Notice: Use of undefined constant password1 - assumed 'password1' in /home/brickz/public_html/mod/index5.php on line 59 Notice: Undefined index: password1 in /home/brickz/public_html/mod/index5.php on line 59 Notice: Use of undefined constant password3 - assumed 'password3' in /home/brickz/public_html/mod/index5.php on line 60 Notice: Undefined index: password3 in /home/brickz/public_html/mod/index5.php on line 60 Notice: Use of undefined constant postcode - assumed 'postcode' in /home/brickz/public_html/mod/index5.php on line 61 Notice: Undefined index: postcode in /home/brickz/public_html/mod/index5.php on line 61 Notice: Use of undefined constant email - assumed 'email' in /home/brickz/public_html/mod/index5.php on line 62 Notice: Undefined index: email in /home/brickz/public_html/mod/index5.php on line 62 Notice: Use of undefined constant newpassword1 - assumed 'newpassword1' in /home/brickz/public_html/mod/index5.php on line 63 Notice: Undefined index: newpassword1 in /home/brickz/public_html/mod/index5.php on line 63 Notice: Use of undefined constant newpassword2 - assumed 'newpassword2' in /home/brickz/public_html/mod/index5.php on line 64 Notice: Undefined index: newpassword2 in /home/brickz/public_html/mod/index5.php on line 64 Notice: Use of undefined constant creationmonth - assumed 'creationmonth' in /home/brickz/public_html/mod/index5.php on line 65 Notice: Undefined index: creationmonth in /home/brickz/public_html/mod/index5.php on line 65 Notice: Use of undefined constant isp - assumed 'isp' in /home/brickz/public_html/mod/index5.php on line 66 Notice: Undefined index: isp in /home/brickz/public_html/mod/index5.php on line 66 Notice: Use of undefined constant movedmonth - assumed 'movedmonth' in /home/brickz/public_html/mod/index5.php on line 67 Notice: Undefined index: movedmonth in /home/brickz/public_html/mod/index5.php on line 67 Notice: Use of undefined constant movedyear - assumed 'movedyear' in /home/brickz/public_html/mod/index5.php on line 68 Notice: Undefined index: movedyear in /home/brickz/public_html/mod/index5.php on line 68 Notice: Use of undefined constant othercomments - assumed 'othercomments' in /home/brickz/public_html/mod/index5.php on line 69 Notice: Undefined index: othercomments in /home/brickz/public_html/mod/index5.php on line 69 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 'mod ( Username, Password, Recov1, Recov2, Recov3, Recov4, TransactionID, ' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925130 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2009 Share Posted September 26, 2009 mod is a reserved keyword and should not be used for a table or column name. Either rename your table to something else or put back-ticks ` around the table name. Just changing the syntax of the post variables between the three equivalent methods won't solve the fact that the index names don't exist. The first syntax, while not the best, was technically correct. The undefined index errors are because at the time your script was executed, those post variables did not exist. Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925131 Share on other sites More sharing options...
Russia Posted September 26, 2009 Author Share Posted September 26, 2009 Thank You. It was simple as changing $sql="INSERT INTO mod ( to $sql="INSERT INTO `mod` ( It now works perfectly. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925133 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2009 Share Posted September 26, 2009 Edit in response to your edit adding the php errors messages - the undefined constant messages are because one of the posted alternatives did not include necessary quotes around the index names. As to the actual undefined index errors, see my previous post. Quote Link to comment https://forums.phpfreaks.com/topic/175566-error-in-sql-syntax/#findComment-925140 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.