我使用this解决方案(已接受的解决方案)不插入重复项,因为我无法设置唯一索引(表属于另一个软件),这样:
$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);
但是我收到以下错误:
列数与第1行的值计数不匹配
如果我在phpMyAdmin中复制查询并替换?使用示例数据查询有效。
有什么问题?
答案 0 :(得分:0)
参数标记(问号)不能用于列名。