/    Sign up×
Community /Pin to ProfileBookmark

Column count doesn’t match value count at row 1

When I try adding a new product to my store using the admin system I made I get this error: Column count doesn’t match value count at row 1
I believe this is where the coding error is but I can’t find the problem.
<?php
if(isset($_POST[‘product_name’])){
$product_name = mysql_real_escape_string($_
POST[‘product_name’]);
$price = mysql_real_escape_string($_POST[‘price’]);
$details = mysql_real_escape_string($_
POST[‘detail’]);
$sql = mysql_query(“SELECT id FROM sale WHERE product_name=’$product_name’ LIMIT 1”);
$productMatch = mysql_num_rows($sql);
if ($productMatch > 0) {
echo ‘ sorry you tried to place a duplicate “Product Name” into the system, <a href=”sale_list.php”>Click Here</a>’;
exit();
}
$sql = mysql_query(“INSERT INTO sale (id, product_name, price, detail)
VALUES(”,’$product_name’,’$price’,’$details’,now())”) or die (mysql_error());
$pid = mysql_insert_id();
$newname = “$pid.jpg”;
move_uploaded_file( $_FILES[‘fileField’][‘tmp_name’], “../product/$newname”);
header(“location: sale_list.php”);
exit();
}
?>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindMar 21.2011 — 
Column count doesn't match value count at row 1
[/QUOTE]


Because the number of columns does not match the number of values here:

[code=php]
$sql = mysql_query("INSERT INTO sale (id, product_name, price, detail)
VALUES('','$product_name','$price','$details',now())") or die (mysql_error());
[/code]


Looks like your missing a timestamp field after detail.
×

Success!

Help @jdd148 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...