gpt4 book ai didi

php - 数据库中的空文本框为 NULL

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

当文本框为空时,我在 UPDATE 中设置空值时遇到问题。这就是我的值(value):

$kod = $_POST['Kod'];
$kod = !empty($kod) ? "'$kod'" : "NULL";

和查询:

$query = "UPDATE Sprzety SET Kod = $kod, Wlasciciel = '$wlasciciel', Konfiguracja = '$konfiguracja' WHERE SprzetID = '$id'";

这里出了什么问题?

最佳答案

您应该使用mysqli_PDO函数。下面是一个 mysqli_ 程序解决方案:

$kod = !empty($_POST['Kod']) ? $_POST['Kod'] : null;

//$link refers to your mysqli_ connection
if ($stmt = mysqli_prepare($link,
"UPDATE UPDATE Sprzety
SET Kod = ?, Wlasciciel = ?, Konfiguracja = ?
WHERE SprzetID = ?")) {

/* bind parameters for markers */
mysqli_stmt_bind_param($stmt, "sssi", $kod, $wlasciciel, $konfiguracja, $id);

/* execute query */
mysqli_stmt_execute($stmt);

关于php - 数据库中的空文本框为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12864236/

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