Jump to content

MySQL and PHP Error


eskimo42

Recommended Posts

I am having a little problem adding some form data to a mySQL database... I have many variables which I am parsing from the form like this:

 

$BillAddress1 = $_POST['BillAddress1'];

$BillSuiteApt = $_POST['BillSuiteApt'];

$BillCity = $_POST['BillCity'];

$Billstate = $_POST['Billstate'];

$BillZip = $_POST['BillZip'];

$BillPhone = $_POST['BillPhone'];

 

Etc.. Many more, but that is how I am doing it... So after my validation code runs I have been trying to do this:

 

//VALIDATION CODE RUNS IF RETURNS NO ERRORS THEN...

 

else

    {

 

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$sql = "INSERT INTO customers (OrderNum, OrderStatus, OrderHow, OrderDate, IP, QtySet, QtyPd, QtyGs, QtyLf, QtyCds, QtyBdmm, QtyMes, Price, Tax, Shipping, Total, Email, ShipFname, ShipLname, ShipCompany, ShipAddress, ShipAddress1, ShipCountry, ShipSuiteApt, ShipCity, ShipState, ShipZip, ShipPhone, BillFName, BillLName, BillCompany, BillAddress, BillAddress1, BillCountry, BillSuiteApt, BillCity, BillState, BillZip, BillPhone, PmtMethod, CheckNum, HearAboutUs, ShipMeth, Tracking, OrderComments, CCName, CCType, CCNumber, CCExpM, CCExpY, CVV2, ChargeDate, AuthNum)

 

VALUES ('','$OrderHow','$Orderdate','$ip','$qtyset','$qtypd','$qtygs','$qtyLf','$QtyCds','$Qtybdmm','$qtymes','$price','$tax','$shipping','$total','$email','$ShipFname','$shipLname','$ShipCompany','$shipAddress','$ShipAddress1','$ShipCountry','$ShipSuiteApt','$ShipCity','$ShipState','$ShipZip','$shipphone','$billFname','$BillLname','$BillCompany','$BillAddress','$billaddress1','$Billcountry','$Billsuiteapt','$Billcity','$Billstate','$Billzip','$BillPhone','','','$hear','','','','$CCName','$CCType','$CCNumber','$CCExpM','$CCExpY','$CVV2','','')";

 

mysql_query($sql);

 

mysql_close();

 

 

 

echo "Thank You for your order!";

 

}

 

For one reason or another it is saying Thank you for your order, but nothing is being added into my mySQL DB.... Any help would be much appreciated to try and get the data in there! I don't know if this matters but OrderNum is an auto-increment and some of the other fields are INT, and VARCHAR. Thanks

 

 

-Evan Klein

Link to comment
Share on other sites

Hmm think i have that taken care of... but

 

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 '','Web','Tue Mar 27','67.186.160.33','','','','','','','','','','','','Evan.Klei' at line 1

Link to comment
Share on other sites

I think from that error it means you have too many columns listed in your query that doesn't match the number of columns you have in your customers table. How many columns do you have in your query and how many do you have in the customers table?

 

From looking at your query you have 53 columns. Is that correct in your database?

 

Also I notice you use blank values in your query. If you are not going to insert a value for a column then don't include it in your query.

Link to comment
Share on other sites

Yes I found why it was giving me the first error the colums were not matched up to the right amount of values... FIXED

 

Now this..

 

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 '','Web','Tue Mar 27','67.186.160.33','','','','','','','','','','','','Evan.Klei' at line 1

 

I also got rid of the values that are blank, but all those empty values above are products which i stored each one as a variable. So $QtySet = 1 then it would but a 1 in the mysql Field QtySet however i made 7 fields for my 7 products and they might only order one product. Is this a bad way to store what they order by using a diff field for each product and having a numeric value to let me know the quantity?

 

 

Thank you very much for the help :-)

 

 

Link to comment
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.