gpt4 book ai didi

php - php mysql 中的 if 语句

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

我的表单编辑数据库中的表。但是,用户可能不会选择图像,因此如果他们不选择,我就不想更新该字段。我尝试了几种方法来做到这一点,但没有任何效果。有简单的方法吗?谢谢。

if ($_POST["image"]!=='') { 
$image= "image=%s";
$imageValue = "GetSQLValueString(".$_POST['image'].", 'text'),";
};

$insertSQL = sprintf("UPDATE taxi SET name=%s, taxi_link=%s, ". $image." WHERE id=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['link'], "text"),
$imageValue,
GetSQLValueString($_POST['id'], "int"));

最佳答案

如果我理解正确的话,你不能把整个事情都放在 if 语句中吗?

if ($_POST["image"]!=='') { 
$image= "image=%s";
$imageValue = "GetSQLValueString(".$_POST['image'].", 'text'),";
$insertSQL = sprintf("UPDATE taxi SET name=%s, taxi_link=%s, ". $image." WHERE id=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['link'], "text"),
$imageValue,
GetSQLValueString($_POST['id'], "int"));
//execute query
} else {
//tell the user nothing happened
} //no semicolon required

现在,如果指定了图像,它将构建并执行查询,如果未指定图像,您可以执行其他操作

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

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