2014-09-03 12 views
0

使用PHP中的followning函數來更新表。問題是第二個參數$ work_place不被接受,更新失敗。這是我第一次使用PHP和MySQL,所以我的知識有限。PHP如何使用多個參數並使用它們更新mySQL表

public function timestampOut($work_done, $work_place) 
    { 
     // clean the input to prevent for example javascript within the notes. 
     $work_done = strip_tags($work_done); 
     $work_place = strip_tags($work_place); 


     $userLastTimestampID = $this->getUserLastTimestampID(); 

     $sql = "UPDATE timestamps SET timestamp_work_description = :work_done, timestamp_work_dropdown = :work_place, timestamp_out = now() WHERE timestamp_id = $userLastTimestampID[0] AND user_id = :user_id"; 
     $query = $this->db->prepare($sql); 
     $query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id'])); 



     $count = $query->rowCount(); 
     if ($count == 1) { 
      return true; 
     } else { 
      $_SESSION["feedback_negative"][] = FEEDBACK_NOTE_CREATION_FAILED; 
     } 
     // default return 
     return false; 
    } 

回答

2

你只需要work_place添加到參數數組在執行調用,就像這樣:

$query->execute(array(':work_done' => $work_done, ':work_place' => $work_place, ':user_id' => $_SESSION['user_id'])); 
0

請仔細閱讀再怎麼execute作品。你會想用這樣的:

$query->execute(array(':work_done' => $work_done, ':work_place' => $work_place, ':user_id' => $_SESSION['user_id'])); 
0

嘗試更換

$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id'])); 

$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id']), ':work_place' => $work_place); 
相關問題