Click to See Complete Forum and Search --> : Column count doesn't match value count at row 1


RAN
02-07-2010, 01:56 PM
Hi,

I have a problem. I have a table named v2links and columns " id, url, caption, lastcheck, checked, fsize, keyword, type"

When I use this code to update only keyword column, gives me an error "Column count doesn't match value count at row 1 "


The code is:

<form name="auth" method="post" action="./customadd.php">
<textarea name="keywords" cols="30" rows="15"></textarea><br /><br />
<input type="submit" value="add custom words">
</form>';

mysql_query("UPDATE `v2links` SET `lastcheck`='1970-01-01 00:00:00' WHERE `lastcheck`<'1970-01-01 00:00:00'");
if(mysql_errno()) print mysql_error()."\n";
mysql_query("UPDATE `v2links` SET `lastcheck`=DATE_ADD(`lastcheck`,INTERVAL 1 MINUTE)");
if(mysql_errno()) print mysql_error()."\n";

if(isset($_POST['keywords']))
{
$kwds=split("\r\n",$_POST['keywords']);
if(count($kwds))
{

for($i=0;$i<count($kwds);$i++)
{
$kwds[$i]=mysql_real_escape_string(trim($kwds[$i]));
print $kwds[$i].": ";
mysql_query("INSERT INTO `v2links` VALUES(NULL,'".$kwds[$i]."',0)");
if(mysql_error()) print mysql_error()."\n";
else print "success!<br />\n";
}
}
}

print '</div>
</body>
';
?>

Can you help me please?
Thank you in advance
RAN

NogDog
02-08-2010, 03:47 PM
I'm guessing this is the problem:

mysql_query("INSERT INTO `v2links` VALUES(NULL,'".$kwds[$i]."',0)");


Presumably your v2links table has more than 3 columns defined for it, while you are only supplying 3 values. If this is correct, then you need to specify the 3 columns for which those values are being assigned:

mysql_query("INSERT INTO `v2links` (`col1`, `col2`, `col3`) VALUES(NULL,'".$kwds[$i]."',0)");

(Even in case where you supply values for all the columns, it's a good idea to specify the columns anyway, just in case the order in which they are defined in the table definition changes for some reason, a new column is added, etc.)

RAN
02-08-2010, 04:08 PM
Hey tank you for your great help

I'm newbie.

Can you help me to make a form with an insert for one column like 'column url'?
I will make the others, I think...

Thank you for your great help!