Jump to content
MakeWebGames

Ran into an error!


Razor42

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...