gpt4 book ai didi

带有 jquery ajax 的 Php pdo UPDATE 函数

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:27 24 4
gpt4 key购买 nike

我有这段代码 php pdo 用于将值更新到数据库中:

try {        
$DBH = new PDO($dsn, $user, $pass, $opt);
$STH = $DBH->prepare("UPDATE track_aktivnosti SET vrednost = :4, WHERE id_akt = :1, naziv = :3, datum = :2");

$STH->bindParam(':1', $_POST['ajdi']);
$STH->bindParam(':2', $_POST['datum']);
$STH->bindParam(':3', $_POST['tabela']);
$STH->bindParam(':4', $_POST['vrednost']);

但是我得到这个错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 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 'WHERE id_akt = '25', naziv = 'Laza Lazic', datum = '2013-04-01'' at line 1

Data submitted successfully

这里可以探究什么?为什么我不能用这个查询更新 vrednost

最佳答案

你有多个错误:

1) 去掉 WHERE 子句前的逗号:

SET vrednost = :4, WHERE id_akt = :1
^^^^
HERE

2) 去掉 WHERE 子句中的逗号。正确的语法是使用 AND(或 OR):

WHERE id_akt = :1, naziv = :3, datum = :2"
^^^^^ ^^^^^
HERE HERE

应该是:

WHERE id_akt = :1 AND naziv = :3 AND datum = :2"

关于带有 jquery ajax 的 Php pdo UPDATE 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22813024/

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