2017-08-19 124 views
-1
function update($data, $table, $id) 
{ 
    global $conid; 
    //echo $id; 
     /*Assuming array keys are = to database fileds*/ 
     if (count($data) > 0) { 
      foreach ($data as $key => $value) { 

       $value = mysqli_real_escape_string($value); // this is line shows a warning 
       $value = "'$value'"; 
       $updates[] = "$key = $value"; 
      } 
     } 
     $implodeArray = implode(', ', $updates); 
     $sql = ("UPDATE $table SET $implodeArray WHERE id=$id"); 
     mysqli_query($conid, $sql); 


} 

這是所有表單的更新代碼,但它會給出警告。警告只顯示在該行的其他作品完美的我沒有找到爲什麼會發生..mysqli在php中獲取更新數據的警告

+1

什麼是警告信息嗎? –

+0

警告:mysqli_real_escape_string()正好期待2個參數 – Shri

回答

0

由於您使用mysqli_ *功能,那麼你必須包括您連接到數據庫到mysqli_real_escape功能:

您需要改變

$value = mysqli_real_escape_string($value); 

$value = mysqli_real_escape_string($conid, $value); 
+0

。謝謝................. – Shri

+0

不客氣,如果有幫助,請[upvote並接受答案](https://stackoverflow.com/help/someone -answers)快樂編碼! :) –

0

mysql的

$value = mysqli_real_escape_string($value); 

的mysqli //在需要作爲connection object的mysqli 2 perameter和string data

$value = mysqli_real_escape_string($conid,$value);//connection object