错误MySQL服务器版本的正确语法在第1行''附近使用

时间:2016-03-02 11:42:01

标签: php mysql

我想将我的Web应用程序嵌入到服务器中,在localhost中没有问题但是当我把我的应用程序运行它时会出现几个问题。

这是问题

UPDATE HistoriKegiatan SET TglSelesaiPemberkasan = CURDATE(), WaktuSelesaiPemberkasan = CURTIME() WHERE IdHistori = 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 " at line 1

这是我的代码

$idKegiatan = (int) $_GET['idkegiatan'];
$NmKegiatan = $_GET['nmkegiatan'];
$transferto = $_POST['transferto'];

$catatan = $_POST['catatan'];
$tim = $_SESSION['team'];
$username = $_SESSION['user_name'];

$sql = "SELECT Max(IdHistori) as LastHId FROM HistoriKegiatan WHERE IdHistori IN (Select IdHistori from HistoriKegiatan where idKegiatan = $idKegiatan)";

    $result = dbQuery($sql);
    $no = dbNumRows($result);
    $data = dbFetchAssoc($result);
    $lastHId = $data['LastHId'];


$sql = "UPDATE HistoriKegiatan SET TglSelesaiPemberkasan = CURDATE(), WaktuSelesaiPemberkasan = CURTIME() WHERE IdHistori = $lastHId ";
echo $sql;
dbQuery($sql);

任何人都可以帮我解决这个问题吗? 对不起我的英文

2 个答案:

答案 0 :(得分:0)

必须是:WHERE IdHistori = '$lastHId'";

$sql = "UPDATE HistoriKegiatan SET TglSelesaiPemberkasan = CURDATE(), WaktuSelesaiPemberkasan = CURTIME() WHERE IdHistori = '$lastHId'";
echo $sql;

答案 1 :(得分:0)

试试这个

$sql = "SELECT Max(IdHistori) as LastHId FROM HistoriKegiatan WHERE IdHistori IN (Select IdHistori from HistoriKegiatan where idKegiatan = '$idKegiatan')";

$sql = "UPDATE HistoriKegiatan SET TglSelesaiPemberkasan = CURDATE(), WaktuSelesaiPemberkasan = CURTIME() WHERE IdHistori = '$lastHId '";

为你工作