我只是尝试插入新客户,如果他们还不存在。我认为SQL语句有问题,但我也想在PHP中给出上下文:
$sql = "INSERT INTO clients
(`studentEmail`, `studentPassword`, `parentEmail`, `parentPassword`,
`studentFirstName`, `studentLastName`, `studentPhone`, `parentFirstName`,
`parentLastName`, `parentPhone`, `school`)
VALUES ('$studentEmail', '$studentPassword', '$parentEmail',
'$parentPassword', '$studentFirstName', '$studentLastName',
'$studentPhone', '$parentFirstName', '$parentLastName', '$parentPhone', '$school')
SELECT studentEmail
FROM clients
WHERE not exists (select * from clients where studentEmail == '"$studentEmail"')";
最佳答案
在插入数据之前,您应该检查电子邮件是否存在。
$check = mysql_query("SELECT studentEmail FROM clients WHERE studentEmail = '{$studentEmail}';");
if (mysql_num_rows($check) == 0) {
// insert
}