Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/64595-php-error-please-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.