gpt4 book ai didi

mysql - if else mysql 语法

转载 作者:行者123 更新时间:2023-11-29 12:54:08 25 4
gpt4 key购买 nike

有人可以帮我解决这个语法吗?我不知道我做错了什么!

当我尝试执行此代码时:

IF EXISTS(SELECT * FROM user WHERE user_username = '$user_username') 
THEN
UPDATE user SET user_name='$name',user_profession='$profession',user_address='$address',user_avatar='$NewImageName'
ELSE
INSERT INTO user (user_name,user_profession,user_address,user_avatar) VALUES ('$name','$profession','$address','$NewImageName';

我收到以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT * FROM user WHERE user_username = '111') THEN UPDATE user SE' at line 1

我不知道这段代码有什么问题!

最佳答案

您是否尝试过在 INSERT INTO... 语句后添加 END IF

关于mysql - if else mysql 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333627/

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