Reputation:
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
Upvotes: 1
Views: 185
Reputation: 8621
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)");
Upvotes: 0
Reputation: 9689
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.
Upvotes: 0
Reputation: 582
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.
Upvotes: 1