2014-07-23 64 views
0
$sql = "UPDATE Student ". 
      "SET score = $total_score ". 
      "WHERE student_id = $student_id"; 
    $stmt = $mysqli->prepare($sql); 
    $stmt->execute(); 
    $query = "SELECT faculty_id ". 
      "From Student s ". 
      "WHERE student_id =$student_id"; 
    $state =$mysqli->prepare($query); 
    $state->execute(); 
    $state->bind_result($faculty_id); 
    if ($state->fetch()) 
    {if (strpos($faculty_id, '1') > 0) { 
      include ('./Registration_Step_3_Student.php'); 
     } else 
     { 
      include ('./Registration_Step_3_Mentor.php'); 
     } 
    } 

所以每當我嘗試運行我的第二個查詢名爲$狀態,我得到這個錯誤,指出它不能被執行的。我相對較新的SQL和PHP,所以任何幫助,將不勝感激。謝謝!致命錯誤:調用一個成員函數的execute()非對象

+0

將錯誤報告添加到文件頂部 'error_reporting(E_ALL); ini_set('display_errors',1);'看看它是否產生任何東西。 –

+0

可能是'From Student s'中的's' - 你可能按下了'CTRL-S'來保存,但失敗了,輸入's'。這發生在我身上。 –

+0

似乎仍然在網站上產生相同的輸出 – helpmii

回答

1

由於您使用mysqli你應該學會如何正確綁定,請在bind_Param

mysqli_stmt::prepare返回失敗時的虛假讀了,當它永遠不要執行語句:

$sql = "UPDATE Student SET score = ? WHERE student_id = ?"; 
$stmt = $mysqli->prepare($sql); 
if($stmt){ 
    $stmt->bind_param('si', $total_score, $student_id); 
    if($stmt->execute()){ 
     $query = "SELECT faculty_id From `Student s` WHERE student_id = ?"; 
     $state =$mysqli->prepare($query); 
     $stmt->bind_param('i', $student_id); 
     if($state->execute()){ 
      var_dump($state->fetch()); 
     }else{ 
      echo 'SELECT failed'; 
      printf("Error: %s.\n", $state->error); 
     }  
    }else{ 
     echo 'failed to execute UPDATE'; 
    } 
}else{ 
     echo 'failed to prepare() UPDATE \n'; 
     printf("Error: %s.\n", $stmt->error); 

} 

希望這會有所幫助

+0

哦,請仔細檢查你的語法,'SELECT faculty_id從學生的位置where student_id =?'看起來不正確 – meda

相關問題