1

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
1
  • Do you have a session_start(); in the begining? Commented Dec 15, 2014 at 8:20

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! after a couple of hours i need to check for typo`s ;)
It happens, remember (by the way) that you can specify on bindparam the type of var, example numeric or string =) it can help with security
0

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.

1 Comment

It happens to all of us. Last time I spent 4 hours on some problem before realizing I made a typo right at the beginning... :(
0

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)");

Comments

Your Answer

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