1

The below MYSQL INSERT command, using PDO, just fails. And after it fails and reports so, the DROP TABLE command also fails. I just can't get what's wrong with the code :/

$sql = $db2->prepare(
'INSERT INTO citizens_12_01_12
(login, rank, xp, level, citizenship, totalDamage, economySkill, damageToday, strength) 
VALUES 
(:login, :rank, :xp, :citizenship, :totalDamage, :economySkill, :damageToday, :strength)'
);
$sql->bindParam(':strength', $api->strength, PDO::PARAM_INT);
$sql->bindParam(':damageToday', $api->damageToday, PDO::PARAM_INT);
$sql->bindParam(':economySkill', $api->economySkill, PDO::PARAM_INT);
$sql->bindParam(':totalDamage', $api->totalDamage, PDO::PARAM_INT);
//$sql->bindValue(':organization', api->organization, PDO::PARAM_BOOL);
$sql->bindParam(':citizenship', $api->citizenship, PDO::PARAM_STR);
$sql->bindParam(':level', $api->level, PDO::PARAM_INT);
$sql->bindParam(':xp', $api->xp, PDO::PARAM_INT);
$sql->bindParam(':login', $api->login, PDO::PARAM_STR);
$sql->bindParam(':rank', $api->rank, PDO::PARAM_STR);

if ($sql->execute()) {
    echo "Query succeeded.";
} else {
    echo "Query failed.";
    $db2->query("DROP TABLE 'citizens_12_01_12'");
}

Following error in error_log:

PHP Warning:  PDOStatement::execute() [<a href='pdostatement.execute'>pdostatement.execute</a>]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in .../getcitizens.php on line 55

Line 55 is the $sql->execute() line

1
  • Can you post the error? If there isn't one (outputted to you via GUI), check your error log. Commented Jan 12, 2012 at 1:43

1 Answer 1

6

You are missing your variable :level in the insert statement.

It should be:

$sql = $db2->prepare(
'INSERT INTO citizens_12_01_12
(login, rank, xp, level, citizenship, totalDamage, economySkill, damageToday, strength) 
VALUES 
(:login, :rank, :xp, :level, :citizenship, :totalDamage, :economySkill, :damageToday, :strength)'
);
Sign up to request clarification or add additional context in comments.

1 Comment

Jesus. That's why I shouldn't code at almost 2 in the morning! Thankyou kindly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.