Forum Moderators: coopster
I'm getting "Column count doesn't match value count at row 1", but as far as I can tell, I have the same number of columns in the table as in the dataset I'm trying to insert...
Here's the code I've inherited. :)
---code---
session_start();
$ssid = session_id();
$conn = mysql_connect("mysql.site.com", "connection", "string");
mysql_select_db("dbtable", $conn);
$sql = "create table item_table(id int not null primary key auto_increment, product varchar(25), qty int, price float, total float, SID varchar(40), buy_time varchar(35))";
$result = mysql_query($sql,$conn);
if($_POST[product]=="none"){
$total=0;
$price=0;
}
else
$price=600;
$total = $price * $_POST[qty];
$time = time();
$my_time = date("r", $time);
echo "prod=".$_POST[product]."<br>";
echo "qty=".$_POST[qty]."<br>";
echo "price=".$price."<br>";
echo "total=".$total."<br>";
echo "ssid=".$ssid."<br>";
echo "time=".$my_time."<br>";
$sql = "insert into item_table values('', '$_POST[product]', '$_POST[qty]', '$price', '$total', '$ssid', '$my_time')";
echo $sql."<br>";
/// there's an error in the following line, possibly too few/too many columns
$result = mysql_query($sql, $conn) or die(mysql_error());
---/code---
Any insight in this matter would be greatly appreciated.
---code---
session_start();
$ssid = session_id();
$conn = mysql_connect("mysql.site.com", "connection", "string");
mysql_select_db("dbtable", $conn);
$sql = "create table item_table(id int not null primary key auto_increment, product varchar(25), qty int, price float, total float, SID varchar(40), buy_time varchar(35))";
$result = mysql_query($sql,$conn);
if($_POST[product]=="none"){
$total=0;
$price=0;
}
else
$price=600;
$total = $price * $_POST[qty];
$time = time();
$my_time = date("r", $time);
echo "prod=".$_POST[product]."<br>";
echo "qty=".$_POST[qty]."<br>";
echo "price=".$price."<br>";
echo "total=".$total."<br>";
echo "ssid=".$ssid."<br>";
echo "time=".$my_time."<br>";
$sql = "insert into item_table values('', '" . $_POST[product] . "', '" . $_POST[qty] . "', '$price', '$total', '$ssid', '$my_time')";
echo "sql=".$sql."<br>";
/// there's an error in the following line, possibly too few/too many columns
$result = mysql_query($sql, $conn) or die(mysql_error());
---/code---
The 'echos' at the end output this:
prod=ML
qty=2
price=600
total=1200
ssid=extremelylongalphanumer
time=Thu, 18 May 2006 13:16:42 -0700
insert into item_table values('', 'ML', '2', '600', '1200', 'extremelylongalphanumer', 'Thu, 18 May 2006 13:16:42 -0700')
and then...
Column count doesn't match value count at row 1
how many in your table?
[dev.mysql.com...]
If you do not specify a list of column names for INSERT ... VALUES or INSERT ... SELECT, values for every column in the table must be provided by the VALUES list or the SELECT statement. If you do not know the order of the columns in the table, use DESCRIBE tbl_name to find out.
so another option would be to use the column names like so
INSERT INTO tbl_name (col1,col2) VALUES('value1','value2');