gpt4 book ai didi

php - IF NOT EXISTS then INSERT else show message 不工作

转载 作者:行者123 更新时间:2023-11-29 12:37:03 24 4
gpt4 key购买 nike

我有一个包含“引用”的表,其想法是如果引用已经存在,则不会插入。如果它不存在,那么它会插入。但是这段代码不会以任何一种方式插入。请协助。

$dbconn = pg_connect("host=127.0.0.1 dbname=XX user=XX password=XX") or die('Could not connect: ' . pg_last_error());
$query = "IF NOT EXISTS (SELECT reference FROM card WHERE reference = '$reference')
INSERT INTO staff (reference, first_name, last_name, address1, address2, address3, address4)
VALUES ('$reference', '$first_name', '$last_name', '$address1', '$address2', '$address3', '$address4')";

$result = pg_query($query);
if (!$result)
{
echo "Customer update failed!! This ID might already be registered with us. Please go back and check the spelling of your email address.<br><br><input type=\"button\" value=\"Go Back\" onClick=\"history.go(-1);return true;\">";
die;
} else
{
echo "Customer update successful; ";
}

pg_close();

最佳答案

制作 column as Unique .然后 Insert 并且不必担心该行的存在。如果它已经存在,则返回 FALSE。

关于php - IF NOT EXISTS then INSERT else show message 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31355320/

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