2016-03-02 74 views
0

我想嵌入我的web應用程序到服務器,在localhost沒有問題,但是當我把我的應用程序並運行它有幾個問題。錯誤MySQL服務器版本的正確語法使用附近''在第1行

這是問題

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); 

任何人都可以幫我解決這個問題? 對不起,我的英語

+1

瞭解準備小號物業 – Jens

+1

看起來像'$ lastHId'沒有設置 – Jens

+0

請發佈您的數據庫架構 - 表,列等 –

回答

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 '"; 

其對你的工作

+0

你的第一個語句將給出一個語法錯誤 – andrewsi

+0

請告訴錯誤 –

+0

雙引號字符串中的非轉義雙引號。只需將'$ idKegiatan'換成單引號即可。 – Progrock

0

這必須是:WHERE IdHistori = '$lastHId'";

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

這取決於什麼數據類型IdHistori是。如果它是一個整數,你不需要它 –

相關問題