我正在开发一个项目,使用PHP - Mysqli,我已经使用HTML表单成功地将值插入到我的表中,现在我想更新值。 在我的更新页面中,所有值都是echo out,一旦我单击“提交”按钮,它将保持不变并位于同一页面中。
它说,致命错误:在a上调用成员函数bind_param() 行中没有对象...
我的代码中有任何建议,地点和类型的错误: DB_USER>表:用户,字段:( user_id,fname,laname,uname,pword,email,mobile,address,rdate)。 user_update.php
<?php ini_set('display_errors', 1);
require 'dbcox/conf.php';
require 'function/security.php';
?>
<?php
$user_id = $_GET['user_id'];
if(isset($_GET['user_id'])){
$update = $db->prepare("UPDATE users SET (fname=?, lname=?, uname=?, pword=?, email=?, mobile=?, address=?, WHERE user_id=? ");
$update->bind_param('sssssss', $fname, $lname, $uname, $pword, $email, $mobile, $address);
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uname = $_POST['uname'];
$pword = $_POST['pword'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$address = $_POST['address'];
if($update->execute()){
echo 'Successfully updated';
}else{
'Failed to update!!';
}
}
答案 0 :(得分:1)
您没有向bind_param提供user_id
<?php ini_set('display_errors', 1);
require 'dbcox/conf.php';
require 'function/security.php';
?>
<?php
$user_id = $_GET['user_id'];
if(isset($_GET['user_id'])){
$update = $db->prepare("UPDATE users SET fname=?, lname=?, uname=?, pword=?, email=?, mobile=?, address=? WHERE user_id=? ");
$update->bind_param('ssssssss', $fname, $lname, $uname, $pword, $email, $mobile, $address, $user_id);
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uname = $_POST['uname'];
$pword = $_POST['pword'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$address = $_POST['address'];
if($update->execute()){
echo 'Successfully updated';
}else{
'Failed to update!!';
}
}
答案 1 :(得分:1)
您的SQL语法有错误,如果echo $db->error;
返回$db->prepare()
false
,您会发现错误。您在分配列表前有一个额外的(
,在最后一个分配后有一个额外的,
。它应该是:
$update = $db->prepare("UPDATE users SET fname=?, lname=?, uname=?, pword=?, email=?, mobile=?, address=? WHERE user_id=? ");
你也忘了绑定user_id
param。
$update->bind_param('ssssssss', $fname, $lname, $uname, $pword, $email, $mobile, $address, $user_id);
答案 2 :(得分:0)
<?php ini_set('display_errors', 1);
require 'dbcox/conf.php';
require 'function/security.php';
?>
<?php
$user_id = $_GET['user_id'];
if(isset($_GET['user_id'])){
$update = $db->prepare("UPDATE users SET (fname=?, lname=?, uname=?, pword=?, email=?, mobile=?, address=? WHERE user_id=? ");
$update->bind_param('ssssssss', $fname, $lname, $uname, $pword, $email, $mobile, $address, $user_id);
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uname = $_POST['uname'];
$pword = $_POST['pword'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$address = $_POST['address'];
$update->execute()
if($update->errno()){
echo "FAILURE!!! " . $update->error;
}
else
echo "Updated {$update->affected_rows} rows";
$update->close();
}