Jump to content

PDO insert in to {HELP!}


Freid001

Recommended Posts

Not sure what is wrong here: 

 

$query = "INSERT INTO `*******`(`account`, `capital`, `image`, `government`, `oil`, `wood`, `copper`, `iron`, `steel`, `titanium`) VALUES(:account, :capital, :image, :government, :oil, :wood, :copper, :iron, :steel, :titanium)";
$statement = $db->prepare($query);
$statement->execute(array(':account' => $user, ':capital' => $capital, ':image' => $image, ':government' => $government, ':oil' => $oil, ':wood' => $wood, ':cooper' => $copper, ':iron' => $iron, ':steel' => $steel, ':titanium' => $titanium));

 

 

THIS IS THE ERROR I GET:

 

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in/srv/disk5/657046/www/worldwarfare-v3.atwebpages.com/pages/registration/registration_script.php on line 175


Thanks for any help :)

Link to comment
https://forums.phpfreaks.com/topic/278483-pdo-insert-in-to-help/
Share on other sites

Ok so no errors show up now. However i'm not sure if the query is being run because nothing gets inserted in to the database. I have checked that it is the correct table name and everything, so not sure why it is not inserting in to the table. Any ideas, or help? 

Not sure why but its like the code is not being executed or something, any ideas? 

 

$query = "INSERT INTO `*******`(`account`, `capital`, `image`, `government`, `oil`, `wood`, `copper`, `iron`, `steel`, `titanium`) VALUES(:account, :capital, :image, :government, :oil, :wood, :copper, :iron, :steel, :titanium)";
$statement = $db->prepare($query);
$statement->execute(array(':account' => $user, ':capital' => $capital, ':image' => $image, ':government' => $government, ':oil' => $oil, ':wood' => $wood, ':copper' => $copper, ':iron' => $iron, ':steel' => $steel, ':titanium' => $titanium));

Try capturing errors. Check my signature where it says Debugging your SQL. You're not checking for any MySQL errors.

 

Edit: The post describes using mysqli, but you'll do the same thing with the appropriate PDO functions. Check the PHP manual for those.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.