eskimo42 Posted March 27, 2007 Share Posted March 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 There may be a problem with your query. Change this line: mysql_query($sql); to: mysql_query($sql) or die('There is a a problem with the query: <pre>' . $sql . '</pre><br />' . mysql_error()); Quote Link to comment Share on other sites More sharing options...
eskimo42 Posted March 27, 2007 Author Share Posted March 27, 2007 There is a a problem with the query: Column count doesn't match value count at row 1 Quote Link to comment Share on other sites More sharing options...
eskimo42 Posted March 27, 2007 Author Share Posted March 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
eskimo42 Posted March 27, 2007 Author Share Posted March 27, 2007 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 :-) Quote Link to comment Share on other sites More sharing options...
fenway Posted April 4, 2007 Share Posted April 4, 2007 Could you post the echo output of $sql? Quote Link to comment 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.