m_tyhurst2002 Posted August 13, 2007 Share Posted August 13, 2007 Hello! I am pretty new to this PHP thing. I have a for and I am submitting fields to database. I get 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 '')' at line 1 This is my code: <?php $con = mysql_connect("localhost","myuserid","mypassword"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("letst5_cwg", $con); //Replace with your MySQL DB Name $BuyerFirstName=mysql_real_escape_string($_POST['BuyerFirstName']); //This value has to be the same as in the HTML form file $BuyerLastName=mysql_real_escape_string($_POST['BuyerLastName']); //This value has to be the same as in the HTML form file $BuyerSSN=mysql_real_escape_string($_POST['BuyerSSN']); $BuyerDOB=mysql_real_escape_string($_POST['BuyerDOB']); $BuyerEmail=mysql_real_escape_string($_POST['BuyerEmail']); $BuyerReEnterEmail=mysql_real_escape_string($_POST['BuyerReEnterEmail']); $BuyerAddress=mysql_real_escape_string($_POST['BuyerAddress']); $BuyerCity=mysql_real_escape_string($_POST['BuyerCity']); $BuyerState=mysql_real_escape_string($_POST['BuyerState']); $BuyerZip=mysql_real_escape_string($_POST['BuyerZip']); $BuyerEmployerName=mysql_real_escape_string($_POST['BuyerEmployerName']); $BuyerEmployerAddress=mysql_real_escape_string($_POST['BuyerEmployerAddress']); $BuyerEmployerCity=mysql_real_escape_string($_POST['BuyerEmployerCity']); $BuyerEmployerState=mysql_real_escape_string($_POST['BuyerEmployerState']); $BuyerEmployerZip=mysql_real_escape_string($_POST['BuyerEmployerZip']); $BuyerYearsEmployed=mysql_real_escape_string($_POST['BuyerYearsEmployed']); $BuyerMonthlyIncome=mysql_real_escape_string($_POST['BuyerMonthlyIncome']); $BuyerOtherIncome=mysql_real_escape_string($_POST['BuyerOtherIncome']); $CoBuyerFirstName=mysql_real_escape_string($_POST['CoBuyerFirstName']); //This value has to be the same as in the HTML form file $CoBuyerLastName=mysql_real_escape_string($_POST['CoBuyerLastName']); //This value has to be the same as in the HTML form file $CoBuyerSSN=mysql_real_escape_string($_POST['CoBuyerSSN']); $CoBuyerDOB=mysql_real_escape_string($_POST['CoBuyerDOB']); $CoBuyerEmail=mysql_real_escape_string($_POST['CoBuyerEmail']); $CoBuyerReEnterEmail=mysql_real_escape_string($_POST['CoBuyerReEnterEmail']); $CoBuyerAddress=mysql_real_escape_string($_POST['CoBuyerAddress']); $CoBuyerCity=mysql_real_escape_string($_POST['CoBuyerCity']); $CoBuyerState=mysql_real_escape_string($_POST['CoBuyerState']); $CoBuyerZip=mysql_real_escape_string($_POST['CoBuyerZip']); $CoBuyerEmployerName=mysql_real_escape_string($_POST['CoBuyerEmployerName']); $CoBuyerEmployerAddress=mysql_real_escape_string($_POST['CoBuyerEmployerAddress']); $CoBuyerEmployerCity=mysql_real_escape_string($_POST['CoBuyerEmployerCity']); $CoBuyerEmployerState=mysql_real_escape_string($_POST['CoBuyerEmployerState']); $CoBuyerEmployerZip=mysql_real_escape_string($_POST['CoBuyerEmployerZip']); $CoBuyerYearsEmployed=mysql_real_escape_string($_POST['CoBuyerYearsEmployed']); $CoBuyerMonthlyIncome=mysql_real_escape_string($_POST['CoBuyerMonthlyIncome']); $CoBuyerOtherIncome=mysql_real_escape_string($_POST['CoBuyerOtherIncome']); $VehicleInfoYear=mysql_real_escape_string($_POST['VehicleInfoYear']); $VehicleInfoMake=mysql_real_escape_string($_POST['VehicleInfoMake']); $VehicleInfoModel=mysql_real_escape_string($_POST['VehicleInfoModel']); $VehicleInfoColor=mysql_real_escape_string($_POST['VehicleInfoColor']); $VehicleInfoEquipment=mysql_real_escape_string($_POST['VehicleInfoEquipment']); $VehicleInfoComments=mysql_real_escape_string($_POST['VehicleInfoComments']); $TradeInYear=mysql_real_escape_string($_POST['TradeInYear']); $TradeInMake=mysql_real_escape_string($_POST['TradeInMake']); $TradeInModel=mysql_real_escape_string($_POST['TradeInModel']); $TradeInColor=mysql_real_escape_string($_POST['TradeInColor']); $TradeInMiles=mysql_real_escape_string($_POST['TradeInMiles']); $TradeInCondition=mysql_real_escape_string($_POST['TradeInCondition']); $TradeInEquipment=mysql_real_escape_string($_POST['TradeInEquipment']); $sql="INSERT INTO data (BuyerFirstName,BuyerLastName,BuyerSSN,BuyerDOB,BuyerEmail,BuyerReEnterEmail,BuyerAddress,BuyerCity,BuyerState,BuyerZip,BuyerEmplyerName,BuyerEmployerAdress,BuyerEmployerCity,BuyerEmployerState,BuyerEmployerZip,BuyerYearsEmployed,BuyerMonthlyIncome,BuyerOtherIncome,CoBuyerFirstName,CoBuyerLastName,CoBuyerSSN,CoBuyerDOB,CoBuyerEmail,CoBuyerReEnterEmail,CoBuyerAddress,CoBuyerCity,CoBuyerState,CoBuyerZip,CoBuyerEmplyerName,CoBuyerEmployerAdress,CoBuyerEmployerCity,CoBuyerEmployerState,CoBuyerEmployerZip,CoBuyerYearsEmployed,CoBuyerMonthlyIncome,CoBuyerOtherIncome,VehicleInfoYear,VehicleInfoMake,VehicleInfoModel,VehicleInfoColor,VehicleInfoEquipment,VehicleInfoComments,TradeInYear,TradeInMake,TradeInModel,TradeInColor,TradeInMiles,TradeInCondition,TradeInEquipment) VALUES ('$BuyerFirstName','$BuyerLastName','$BuyerFirstName','$BuyerLastName','$BuyerSSN','$BuyerDOB','$BuyerEmail','$BuyerReEnterEmail','$BuyerAddress','$BuyerCity','$BuyerState','$BuyerZip','$BuyerEmplyerName','$BuyerEmployerAdress','$BuyerEmployerCity','$BuyerEmployerState','$BuyerEmployerZip','$BuyerYearsEmployed','$BuyerMonthlyIncome','$BuyerOtherIncome','$CoBuyerFirstName','$CoBuyerLastName','$CoBuyerSSN','$CoBuyerDOB','$CoBuyerEmail','$CoBuyerReEnterEmail','$CoBuyerAddress','$CoBuyerCity','$CoBuyerState','$CoBuyerZip','$CoBuyerEmplyerName','$CoBuyerEmployerAdress','$CoBuyerEmployerCity','$CoBuyerEmployerState','$CoBuyerEmployerZip','$CoBuyerYearsEmployed','$CoBuyerMonthlyIncome','$CoBuyerOtherIncome','$VehicleInfoYear','$VehicleInfoMake','$VehicleInfoModel','$VehicleInfoColor','$VehicleInfoEquipment','$VehicleInfoComments','$TradeInYear','$TradeInMake','$TradeInModel','$TradeInColor','$TradeInMiles','$TradeInCondition','$TradeInEquipment)"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The form data was successfully added to your database."; mysql_close($con); ?> When I use this I get the error above. There is 47 fields that is in the mysql database. When I edit the PHP code and only use the first two ($BuyerFirstName and $BuyerLastName) it successfully loads to the mysql database. It is when I add the other 45 fields to the code that I get the error posted above. I do not understand what is going on. Can you please help me, someone? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/ Share on other sites More sharing options...
trq Posted August 13, 2007 Share Posted August 13, 2007 You are missing the last ' around $TradeInEquipment. Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322047 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 just to keep you from going batty look into the foreach for those $_POST instead of having to escape each individually a loop can do it for u Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322049 Share on other sites More sharing options...
m_tyhurst2002 Posted August 13, 2007 Author Share Posted August 13, 2007 Thanks SOOOO much!!! I missed that... Now it says: Error: Column count doesn't match value count at row 1 Do you know what that might mean/be? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322050 Share on other sites More sharing options...
trq Posted August 13, 2007 Share Posted August 13, 2007 It means you have either too many or too few VALUES for the fields provided. Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322052 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 in teh errror part echo out $sql and see what it says Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322053 Share on other sites More sharing options...
m_tyhurst2002 Posted August 13, 2007 Author Share Posted August 13, 2007 How do you echo out $sql? I am sorry, I don't know what I am doing. Trying to learn though. Also, how do I know what to put in as far as the values go for the 47 fields? Thanks for your patience guys... Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322060 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 replace name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } with mysql_query($sql) or die("Error: <br/>: ".$sql); Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322062 Share on other sites More sharing options...
m_tyhurst2002 Posted August 13, 2007 Author Share Posted August 13, 2007 Ok. I replaced that and got this error: Warning: Unterminated comment starting line 58 in /home/letst5/public_html/consumerworldgroup/submit.php on line 58 How do I find out what is undetermined? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322064 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 just put $sql in teh () then Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322066 Share on other sites More sharing options...
m_tyhurst2002 Posted August 13, 2007 Author Share Posted August 13, 2007 Sorry to be repetative but I don't understand where to put the "$sql in teh () then". Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64595-php-error-please-help/#findComment-322253 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.