gpt4 book ai didi

php - 在插入数据之前检查现有条目

转载 作者:行者123 更新时间:2023-11-29 04:27:33 24 4
gpt4 key购买 nike

只有当新客户不存在时,我才尝试插入新客户。我认为 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"')";

最佳答案

在插入语句中,selectvalues 是互斥的。而不是:

insert table1 (col1, col2, col3, ...)
values (1, 2, 3, ...)
select col1
where not exists (...)

尝试:

insert table1 (col1, col2, col3, ...)
select 1, 2, 3, ...
where not exists (...)

关于php - 在插入数据之前检查现有条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8566569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com