2013-02-06 216 views
-3

上我有一個錯誤說調用一個成員函數mysql_affected_rows()函數的非對象

調用一個成員函數mysql_affected_rows()函數在C非對象:\ XAMPP \ htdocs中\ 189線上的initializr \ search.php

當我點擊我的提交按鈕。

if(isset($_POST['select'])) { 
    $studId = $_REQUEST['studid']; 

    foreach ($studId as $ch) { 
     $result = $mysqli->query("INSERT INTO tbl_tempCand (datetime, names) VALUES (CURRENT_TIMESTAMP(), '".$ch."')"); 
     //this is my line 189 error 
     if($row->mysql_affected_rows($result)==0) { 
      header("Location: registercand.php"); 
     } else { 
      echo "nothing happen"; 
     } 
    } 
} 

這是爲什麼?

+0

首先,請不要使用mysql_ *功能,它們'已正式棄用。其次,您的查詢似乎對SQL注入攻擊開放。改用準備好的陳述或參數化查詢。 –

回答

0

使用此查詢

$result = $mysqli->query("INSERT INTO tbl_tempCand (`datetime`, `names`) VALUES (CURRENT_TIMESTAMP(), '".$ch."')"); 
                ^// here was the problem 

datetime保留字mysql和因爲查詢失敗的。如果你想使用這種保留字作爲列引用他們這``

變化的內部

if($row->mysql_affected_rows($result)==0) 

if($mysqli->affected_rows > 0) 
+0

它給了我同樣的錯誤指向如果($行 - > mysql_affected_rows($結果)== 0)不在我的查詢... –

+0

@PotPot實際上你的查詢失敗,它給你沒有結果,因此它給錯誤在這裏'mysql_affected_rows($ result)' –

+0

所以我應該怎麼做,當我的查詢成功,它會重定向到另一個表單?..請給我一些建議先生... –

相關問題