2013-03-19 69 views
1

有人請指出我出錯的地方。更新mysqli錯誤

我試着按照如何執行update-with-mysqli-prepare給出的建議?在網站上,但沒有運氣。

以下:

<?php 

//connection 
$con = new mysqli ("localhost","user","password","db"); 

$playno = "22"; 
$n1 = "4"; 
$n2 = "4"; 
$n3 = "4"; 

$stmt = $con -> prepare("UPDATE game SET no1 = ?, no2 = ?, no3 = ? WHERE id = ?"); 

$stmt -> bind_param ('iiii',"$n1","$n2","$n3","$playno"); 
$stmt -> execute(); 


?> 

在瀏覽器中給出了這樣的:

Fatal error: Cannot pass parameter 2 by reference in C:\xampp\htdocs... on line 13

提前非常感謝。

回答

2
$stmt -> bind_param ('iiii',$n1,$n2,$n3,$playno); 
+0

非常感謝您! – user2184481 2013-03-19 00:16:58

0

該錯誤表示bind_param中的第二個參數應該是對變量的引用。

$stmt -> bind_param ('iiii',"$n1","$n2","$n3","$playno"); 

this

Note that mysqli_stmt_bind_param() requires parameters to be passed by reference

它應該是:$stmt -> bind_param ('iiii',$n1,$n2,$n3,$playno);

0

當您嘗試通過PARAMS如下

$stmt -> bind_param ('iiii',"$n1","$n2","$n3","$playno"); 

"$n1"等被視爲常數字符串,因此導致錯誤(而不是警告)。

此外,您需要傳遞整數值而不是字符串。

$stmt -> bind_param('iiii',$n1, $n2, $n3, $playno); 
0
$stmt -> bind_param ('iiii',"$n1","$n2","$n3","$playno"); 

應該

$stmt -> bind_param ('ssss',$n1,$n2,$n3,$playno); 

$playno = 22; 
$n1 = 4; 
$n2 = 4; 
$n3 = 4; 

$stmt -> bind_param ('iiii',$n1,$n2,$n3,$playno); 
-1

你的問題很簡單:

這是一個字符串 $ playno = 「22」; // string $ n1 =「4」; // string $ n2 =「4」; // string $ n3 =「4」; //字符串

$stmt = $con -> prepare("UPDATE game SET no1 = ?, no2 = ?, no3 = ? WHERE id = ?"); 

這裏你的錯誤 $語句 - > bind_param( 'IIII', 「$ N1」, 「$ N2」, 「$ N3」, 「$ playno」); //失敗,您必須使用s $ stmt - > bind_param('ssss',$ n1,$ n2,$ n3,$ playno); //這是正確的

或變化:

$playno = 22; //integer 
$n1 = 4; //integer 
$n2 = 4; //integer 
$n3 = 4; //integer 
$stmt -> bind_param ('iiii',$n1,$n2,$n3,$playno); //this is correct 

然後:

$stmt -> execute();