ric
ric

Reputation: 11

How to make a prepared statement with php variables and php array elements?

I know this is just some annoying syntax thing but i just can't get the code below to work. Please can someone help?

if($stmt = $link -> prepare("INSERT INTO google_pre_transaction VALUES    (?,?,?,?,?,?,?,?,?,?,?,?,?")) {
  /* Bind parameters
     s - string, b - boolean, i - int, etc */
  $stmt -> bind_param("iiisss", 
  $m_id,
  $page_one['input-one'], 
  $page_one['input-two'],
  $page_one['title'],
  $page_one['first'], 
  $page_one['last']
  );

Upvotes: 1

Views: 190

Answers (2)

Nanne
Nanne

Reputation: 64399

For one, you have a lot more ? then you have parameters in you bind_param. They should be the same amount.

I'm guessing the error is saying exactly that by the way.

Upvotes: 1

rockerest
rockerest

Reputation: 10508

You have 13 ? and 7 variables. The numbers have to match.

Also, your closing parenthese is outside the quote, which is bad syntax.

This should work:

prepare("INSERT INTO google_pre_transaction VALUES (?,?,?,?,?,?,?)")

Upvotes: 2

Related Questions