Razor42 Posted August 16, 2012 Posted August 16, 2012 Hi there, ran into an error and really strugling to fix it. If someone could help that would be great! The error is: QUERY ERROR: Column count doesn't match value count at row 1 Query was INSERT INTO dogs VALUES('Pitbull', 'Male', '100') Here is the function in which the error occured: function adddog() { global $db, $ir, $c, $h, $userid; $cost=abs((int) $_POST['dogscost']); $strength=abs((int) $_POST['dogsstrength']); $endurance=abs((int) $_POST['dogsendurance']); $speed=abs((int) $_POST['dogsspeed']); $guard=abs((int) $_POST['dogsguard']); if($_POST['dogsbreed'] && $cost) { $db->query("INSERT INTO dogs VALUES('{$_POST['dogsbreed']}', '{$_POST['dogsgender']}', '$cost')"); $db->query("INSERT INTO dogsstats VALUES('$strength', '$endurance', '$speed', '$guard')"); print "Dog {$_POST['dogsbreed']} added."; stafflog_add("Added dog {$_POST['dogsbreed']}"); } else { print "<h3>Add Dog</h3><hr /> <form action='staff_dogs.php?action=adddog' method='post'> Breed: <input type='text' name='dogsbreed' /><br /> Gender (Male/Female): <input type='text' name='dogsgender' /><br /> Cost (Money): <input type='text' name='dogscost' /><br /> Strength: <input type='text' name='dogsstrength' /><br /> Guard: <input type='text' name='dogsguard' /><br /> Endurance: <input type='text' name='dogsendurance' /><br /> Speed: <input type='text' name='dogsguard' /><br /> <input type='submit' value='Add Dog' /></form>"; } } Would be great if someone could help me out here. Quote
Seker Posted August 16, 2012 Posted August 16, 2012 Hi there, ran into an error and really strugling to fix it. If someone could help that would be great! The error is: QUERY ERROR: Column count doesn't match value count at row 1 Query was INSERT INTO dogs VALUES('Pitbull', 'Male', '100') Here is the function in which the error occured: function adddog() { global $db, $ir, $c, $h, $userid; $cost=abs((int) $_POST['dogscost']); $strength=abs((int) $_POST['dogsstrength']); $endurance=abs((int) $_POST['dogsendurance']); $speed=abs((int) $_POST['dogsspeed']); $guard=abs((int) $_POST['dogsguard']); if($_POST['dogsbreed'] && $cost) { $db->query("INSERT INTO dogs VALUES('{$_POST['dogsbreed']}', '{$_POST['dogsgender']}', '$cost')"); $db->query("INSERT INTO dogsstats VALUES('$strength', '$endurance', '$speed', '$guard')"); print "Dog {$_POST['dogsbreed']} added."; stafflog_add("Added dog {$_POST['dogsbreed']}"); } else { print "<h3>Add Dog</h3><hr /> <form action='staff_dogs.php?action=adddog' method='post'> Breed: <input type='text' name='dogsbreed' /><br /> Gender (Male/Female): <input type='text' name='dogsgender' /><br /> Cost (Money): <input type='text' name='dogscost' /><br /> Strength: <input type='text' name='dogsstrength' /><br /> Guard: <input type='text' name='dogsguard' /><br /> Endurance: <input type='text' name='dogsendurance' /><br /> Speed: <input type='text' name='dogsguard' /><br /> <input type='submit' value='Add Dog' /></form>"; } } Would be great if someone could help me out here. Hint: Count the columns of your `dogs` table. Quote
Razor42 Posted August 16, 2012 Author Posted August 16, 2012 My dogs table has many columns. Would creating another table and just adding these columns fix the error? Quote
Seker Posted August 16, 2012 Posted August 16, 2012 My dogs table has many columns. Would creating another table and just adding these columns fix the error? You're not selecting specific columns in your table. Therefore, your query comes up as incomplete. Try something like this instead: $db->query("INSERT INTO dogs (column1,column2,column3) VALUES('{$_POST['dogsbreed']}', '{$_POST['dogsgender']}', '$cost')"); Get it? Quote
Razor42 Posted August 16, 2012 Author Posted August 16, 2012 Just created a new table and now works perfect. Thank you. Quote
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.