function removeMovie($link, $title){
$sth = $link->prepare("DELETE FROM film WHERE title=:title");
$sth->bindValue (':title ', $title, PDO::PARAM_STR);
$sth->execute();
echo 'Removing succeed, Ga back';
var_dump ($sth->errorInfo());
}
I receive the following error message:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid > parameter number: parameter was not defined in D:\Libraries\Documents\ICT\Webprogrammeren\USBWebserver v8.5\8.5\root\Huiswerk\Week 5\functions.php on line 39
$link
is the database connection i'm making
I've searched google for a long time now and I can't find the right answer. A lot of have a typo but I can't seem to find the typo. So it must be something else:
I have a database with two tables which are connected with one and each other through genre_id. Maybe this has something to do when I try to delete it?
Kind regards,
Danny
Related
I'm using PDO to push some data to my MySQL server with table name 'User', and I'm getting the following error:
[26-Mar-2017 22:18:21 America/Chicago] Could not successfully add user!
[26-Mar-2017 22:18:21 America/Chicago] SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
I've looked at multiple other questions on stack overflow with the same error message, and it boils down to PDO prepare and execute having mismatching parameters. But, my prepare and execute is matching, and I have checked so many times, but I'm still getting the errors. Here's my code:
$noMusicScore = $data->noMusicScore;
$classicalMusicScore = $data->classicalMusicScore;
$popMusicScore = $data->popMusicScore;
$hiphopMusicScore = $data->hiphopMusicScore;
try
{
$db = new PDO('info here......');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $db->prepare("INSERT INTO User (no-music-score, classical-music-score, pop-music-score, hiphop-music-score)
VALUES (:no-music-score, :classical-music-score, :pop-music-score, :hiphop-music-score)");
$query->execute(array(':no-music-score' => $noMusicScore, ':classical-music-score' => $classicalMusicScore,
':pop-music-score' => $popMusicScore, ':hiphop-music-score' => $hiphopMusicScore));
error_log("Successfully added user!");
}
catch(PDOException $e)
{
error_log("Could not successfully add user!");
error_log($e->getMessage());
}
unset($db, $query);
I fixed the issue. I simply removed the dashes for the placeholder names and everything fell into place. 'No' is also a SQL keyword, so I think that was part of the issue as well.
I am struggling to find the solution to my error for my project, can someone please assist me and show me the correct way.
Here is my code:
$productkey = $_SESSION['key'];
$productuser = $_SESSION['user'];
$productemail = $_SESSION['email'];
// Include Database Connection
require 'assets/sys/config.php';
$query = dbConnect()->prepare("INSERT INTO _system (_product_key, _product_user, _product_email, _site_email, _site_title) VALUES (:_product_key, :_product_user, :_product_email, :_site_title, :site_email)");
$query->bindParam(':_product_key', $productkey);
$query->bindParam(':_product_user', $productuser);
$query->bindParam(':_product_email', $productemail);
$query->bindParam(':_site_title', $_POST['sitetitle']);
$query->bindParam(':_site_email', $_POST['siteemail']);
$query->execute();
Error I am receiving:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in
In your query you have:
:site_email
But you do bind this:
$query->bindParam(':_site_email', $_POST['siteemail']);
Those are different, edit with:
$query->bindParam(':site_email', $_POST['siteemail']);
Or change the parameter on your sql.
You have a typo in your bound parameters. :site_email instead of :_site_email.
By the way... You know you can do that with a simple hash array, right? Just name the keys the same as the placeholders in the query.
As others have pointed out, there's the typo. But you also have _site_email and _site_title in the wrong order so you won't be inserting the data where you expect.
Should be:
$query = dbConnect()->prepare("INSERT INTO _system (_product_key, _product_user, _product_email, _site_title, _site_email)
VALUES (:_product_key, :_product_user, :_product_email, :_site_title, :_site_email)");
This question already has an answer here:
MysQl error : Invalid parameter number
(1 answer)
Closed 8 years ago.
Its probley something small but i been looking at this for ages and still cant get it to work at all im getting two errors
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in
the code i have is this:
public function getdata ($tran_id)
{
$sql = "SELECT tran_id, seller_user_name, user_name_buyer
FROM trade_transaction, feedback Where feedback.feedback_username = trade.user_name_of_buyer
AND user_name_of_buyer = :user_name_buyer ";
$sth = $this->db->prepare($sql);
$sth->execute(array(':tran_id' => $tran_id, ':user_name_buyer ' => $_SESSION['user_name']));
$user = $sth->fetch();
You're binding a :tran_id parameter during your call to execute, but you're not using that parameter in your query.
Change your execute line to this
$sth->execute(array(':user_name_buyer ' => $_SESSION['user_name']));
Remove :tran_id from your parameter list or add a condition for that parameter. I hope this help.
Your select statement does not have a where clause for tran_id, either remove the tran_id from your execute call
$sth->execute(array(':user_name_buyer ' => $_SESSION['user_name']));
or add a extra where clause to your sql statement
$sql = "SELECT tran_id, seller_user_name, user_name_buyer
FROM trade_transaction, feedback
WHERE feedback.feedback_username = trade.user_name_of_buyer
AND tran_id = :tran_id
AND user_name_of_buyer = :user_name_buyer ";
I'm sure it's obvious, but I can't spot what's wrong with the code below:
$sSQl="SELECT nDocumentID, sFilename, sDescription
FROM tCompanyDocuments
WHERE nCompanyID=:nCompanyID AND sDocumentType='I' ORDER BY nDisplayOrder";
$objQuery=$objConn->prepare($sSQL);
$objQuery->bindParam(':nCompanyID', $arrResult['nCompanyID']);
if ($objQuery->execute()) {
$arrTemp=$objQuery->fetchAll(PDO::FETCH_ASSOC);
if (sizeof($arrTemp)>0) {
foreach ($arrTemp as $objRow) {
//do stuff
}
}
}
The error message is "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in {filename}" and the line referenced is $objQuery->execute()
I've confirmed that $arrResult['nCompanyID'] is populated - what can't I see?
Thanks
How did you verify the $arrResult['nCompanyID'] ?
The query seems to run fine and it returns result. I guess it's the $arrResult['nCompanyID'] that is empty.
Try this:
$sSQl="SELECT nDocumentID, sFilename, sDescription
FROM tCompanyDocuments
WHERE nCompanyID = :nCompanyID AND sDocumentType='I' ORDER BY nDisplayOrder";
if nCompanyID is integer type then:
$objQuery->bindParam(':nCompanyID', $arrResult['nCompanyID'], PDO::PARAM_INT);
or
$objQuery->bindParam(':nCompanyID', $arrResult['nCompanyID'], PDO::PARAM_STR,Length of string);
See details
I have been coding for a few hours on this thing, so I think I am missing something very simple here, but I can't seem to find it.
I am getting these 2 errors
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 77
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 79
public function resetPassword($password, $email){
$rst = $this->db->prepare("insert into users (password) values (?) where email=? ");
$rst->bindParam('?', $password);
$rst->bindParam('?', $email);
$rst->execute();
if($rst->execute()){
return "Password changed!";
}
else echo "Could not change password.";
}
Am I forgetting something?
When using questions marks as placeholders, you send an array to the execute method, like so: $rst->execute(array('placeholder1value', 'placeohlder2value'));
However, if you want to use named placeholders, you would bindParam/bindValue them, like so:
$stmt = $pdo->prepare('INSERT INTO table (key1, key2) VALUES (:key1, :key2)');
$stmt->bindValue(':key1', 'somevalue', PDO::PARAM_STR);
$stmt->bindValue(':key1', 3532, PDO::PARAM_INT);
$stmt->execute();
Please read about the difference between bindParam and bindValue
And another note, your SQL query doesn't make sense, do you mean to do an UPDATE?