gpt4 book ai didi

php - SQL Update else Insert 不工作

转载 作者:行者123 更新时间:2023-11-28 23:30:40 28 4
gpt4 key购买 nike

<分区>

我正在尝试更新 SQL 数据库中的用户详细信息,但是如果该用户的一行不存在,我需要为该用户创建一个(每个用户只能创建一个)它只是不更新​​也不插入。这是以下脚本。

$sql = "IF EXISTS (SELECT * FROM user_details WHERE user_id = $user_id)
UPDATE user_details SET work = $work, education = $education, location = $location, relationship = $relationship, phone = $phone, email = $email, website = $website, language = $language, skill = $skill, tumbkr = $tumblr, instagram = $instagram, skype = $skype, facebook = $facebook, youtube = $youtube, twitter = $twitter, about = $about, user_id = $user_id WHERE user_id = $user_id
ELSE
INSERT INTO user_details (work, education, location, relationship, phone, email, website, language, skill, tumblr, instagram, skype, facebook, youtube, twitter, about, user_id)";
$q = $conn->prepare($sql);
$q->execute();

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