2013-06-21 120 views
-1

這是一個this question,但它沒有得到答覆。所以我告訴我的故事!mysqli準備語句錯誤(bind_param)

<?php 

include("connect.php"); 

$keyz = $_GET['id']; 

mysqli_real_escape_string($db, $keyz); 

if(!empty($_POST)){ 

    $query = $db->prepare("UPDATE talents SET (firstName,lastName,gender,dob,email,streetAddress,phoneNumber,city,state,country,zip,eyeColor,hairColor,height,weight,chest,waist,hips,dressSize,shoeSize) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) WHERE pk = ?"); 
    $query->bind_param('sssssssssssssssssssss',$_POST['firstName'],$_POST['lastName'],$_POST['gender'],$_POST['dob'],$_POST['email'],$_POST['streetAddress'],$_POST['phoneNumber'],$_POST['city'],$_POST['state'],$_POST['country'],$_POST['zip'],$_POST['eyeColor'],$_POST['hairColor'],$_POST['height'],$_POST['weight'],$_POST['chest'],$_POST['waist'],$_POST['hips'],$_POST['dressSize'],$_POST['shoeSize'],$keyz); 
    $query->execute(); 
    $db->close(); 

    print_r($_POST['firstName'] . " " . $_POST['lastName'] . " has been updated."); 

} 

$query = "SELECT * FROM talents WHERE pk = " . $keyz; 

if(!$result = $db->query($query)){ 
    die('There was an error running the query [' . $db->error . ']'); 
} 

while($row = $result->fetch_assoc()){ 

?> 
. 
. 
. 
On to populate edit form 

Connect.php(這是我的本地開發機器上):

$db = new mysqli('localhost', 'root', '', '[password]'); 

if($db->connect_errno > 0){ 
    die('Unable to connect to database [' . $db->connect_error . ']'); 
} 

而我得到的錯誤:

Fatal error: Call to a member function bind_param() on a non-object in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\FuseTalent\editTalent.php on line 80

我試過在建議什麼danzan另一個問題和var_dump $查詢,但它返回的是bool(false)

我在做什麼錯?我從另一個工作頁面複製/粘貼/調整了代碼。

+0

可能重複[調用成員函數綁定\ _Param()一個非對象(未能解決,儘管研究)(http://stackoverflow.com/questions/6659882/call-to -a-member-function-bind-param-on-a-non-object-unable-to-solve-though) – Rikesh

+0

我其實是[this one]的一個騙局(http://stackoverflow.com/a/15447204/ 285587) –

+0

'我複製/粘貼/調整了另一個工作頁面的代碼。'是的,這是主要問題。 –

回答

1

mysqli->prepare()如果出現問題,則返回FALSE。這將導致調用{FALSE}->bindParam(...);,這將解釋錯誤消息call to a member function ... on a non-object
添加更多的錯誤處理您的腳本

$query = $db->prepare("UPDATE talents SET ..."); 
if (!$query) { 
    // something went wrong 
    // $db->errno and $db->error should contain more information about the error 
    // see http://docs.php.net/manual/en/mysqli.error.php 
    ... 
} 

也看一看的MySQL UPDATE syntax。這是

UPDATE talents SET 
firstName=?, 
lastName=?, 
... 
WHERE 
... 
+0

返回語法錯誤。你不能捆綁像插入的值? – Christopher

+0

繁瑣的重做sql的確有竅門。 *不明智,*不捆綁價值更新!! ** – Christopher

+0

你的MySQL服務器和文檔都說「不」,所以顯然你不能;-) – VolkerK