gpt4 book ai didi

php - 无法将行更新为与当前相同的值吗?

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

我有一个类似的程序

add_action( 'wp_ajax_case_update', 'case_update' );

function case_update ( )
{
$id = $_POST['id'];
$compname = $_POST['compname'];
$casename = $_POST['casename'];
$imageurl = $_POST['imageurl'];
$summary = $_POST['summary'];
$results = $_POST['results'];

$thisAction = $_POST['thisAction'];

$message = "";

switch ($thisAction)
{
case 'add':
{
global $wpdb;
$message .= $wpdb->query("INSERT INTO cases (compname,casename,imageurl,summary,results) VALUES (" . implode(",", array("'$compname'", "'$casename'", "'$imageurl'", "'$summary'", "'$results'")) . ")")
? 'Successfully added case study ' . $casename . ' to the database.'
: 'Error occurred when trying to add case study to database: ' . $wpdb->last_error;
break;
}
case 'delete':
{
global $wpdb;
$message .= $wpdb->query("DELETE FROM cases WHERE id=" . $id)
? 'Successfully deleted case study from the database.'
: 'Error occurred when trying to delete case study from database: ' . $wpdb->last_error;
break;
}
case 'update':
{
global $wpdb;
$message .= $wpdb->query("UPDATE cases SET compname='$compname',casename='$casename',imageurl='$imageurl',summary='$summary',results='$results' WHERE id=$id")
? 'Successfully updated case study.'
: 'Error occurred when trying to update case study in database: ' . $wpdb->last_error;
break;
}
default:
{
$message .= 'Didn\'t recognize action.';
break;
}
}
die($message);
}

我已经在我的 WordPress 主题中构建的许多管理面板中重复使用了这个过程。我在测试过程中刚刚发现,当用户出于某种原因更新到相同值时,case 'update' block 会失败。但由于 $wpdb->last_error; 在发生这种情况时不会打印任何错误,所以我不知道问题到底是什么。

有人解释一下吗?我该如何解决?

最佳答案

将名为 updated 的时间戳列添加到表中,并将 ,updated=now() 添加到 UPDATE 语句中,以便为 update 生成非零值行。

关于php - 无法将行更新为与当前相同的值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32080256/

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