-2

I use this solution (the accepted one) to insert no duplicates, because I can't set an unique index (table belong to another software), this way:

$InsertAddress = $DatabaseConnection -> prepare("INSERT INTO `tt_address` (`pid`, `tstamp`, `first_name`, `last_name`, `email`, `phone`, `address`, `city`, `zip`) SELECT * FROM (SELECT 272 AS `tmp_pid`, ? AS `tmp_tstamp`, ? AS `tmp_first_name`, ? AS `tmp_last_name`, ? AS `tmp_email`, ? AS `tmp_phone`, ? AS `tmp_address`, ? AS `tmp_city`, ? AS `tmp_zip`) AS `tmp` WHERE NOT EXISTS (SELECT `email` FROM `tt_address` WHERE `email` = ?) LIMIT 1")

$InsertAddress -> bind_param('issssssss', $Timestamp, $_POST['firstname'], $_POST['lastname'], $_POST['mail'], $_POST['phone'], $_POST['address'], $_POST['ort'], $_POST['plz'], $_POST['mail']);

$InsertAddress -> execute();

echo($DatabaseConnection -> error);

But I get the following error:

Column count doesn't match value count at row 1

If I copy the query in phpMyAdmin and replace the ? with sample data the query works.

What is wrong?

Community
  • 1
  • 1
Hativ
  • 1,282
  • 1
  • 13
  • 23
  • Try plugging in actual data like you did in phpMyAdmin and see if you're successful. I don't know of any column name that is called a question mark. –  Apr 15 '15 at 02:34

1 Answers1

0

Parameter markers (the question marks) can't be used for column names.

Hativ
  • 1,282
  • 1
  • 13
  • 23