2016-11-27 118 views
0

我測試過它,SESSION ID發出一個有效的ID,所有其他參數也一樣。幫我。PDO查詢不起作用

$sql = 'UPDATE users SET firstname = :firstname, lastname = :lastname WHERE id = :id'; 
$records->bindParam(':id',$_SESSION['user_id']); 

     $stmt = $conn->prepare($sql); 
     list($firstname, $lastname) = explode(' ', $nn); 

     $stmt->bindParam(':firstname', $firstname); 
     $stmt->bindParam(':lastname', $lastname); 

     if($stmt->execute()) { 



     } else { 

      die("An error adapted during changes."); 

     } 
+1

呃...你綁定$記錄,而不是$ stmt的ID。另外,你需要在prepare()之後執行bindParam(); – junkfoodjunkie

回答

0

我以爲你的查詢應該是這樣的。

$sql = 'UPDATE users SET firstname = :firstname,  lastname = :lastname WHERE id = :id' ; 
$stmt = $conn->prepare($sql); 
list($firstname, $lastname) = explode(' ', $nn); 
$stmt->bindParam(':id',$_SESSION['user_id']); 
$stmt->bindParam(':firstname', $firstname); 
$stmt->bindParam(':lastname', $lastname); 
if($stmt->execute()) { 



    } else { 

     die("An error adapted during changes."); 

    }