user6265109 user6265109 - 8 months ago 34
MySQL Question

Getting error for mysqli_stmt_bind_param()

I am using ampps server for my database. Using php I have written script to connect with server database. Now I want to update data in the database table.

I tried writing the script and when I try to update getting error as : mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in.

First parameter is the statement still I get the error.



class updateUserHelper

private $ID;
private $name;
private $email;
private $status;

function updateUserHelper($ID,$name,$email,$status)
$this -> ID = $ID;
$this -> name = $name;
$this -> email = $email;
$this -> status = $status;


function update()
$con = testDatabase::getDB();

echo $this->ID;
echo $this->name;
echo $this->email;
echo $this->status;

$stmt = mysqli_prepare($con,"UPDATE user SET 'name' = ?, 'email' = ?, 'status' = ? where 'ID' = ?");
mysqli_stmt_bind_param($stmt,'ssss',$this->ID, $this->name, $this->email, $this->status);

if (mysqli_stmt_execute($stmt)) {
echo "New record updated successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);



Can anyone help please,very new to php. Thank you..


Two error in your code

1) Use backticks and not single quotes around table and column names

2) Incorrect sequence of bind param . this->ID bind to be at last as you parametrised last in your query

The correct code would be

$stmt = mysqli_prepare($con,"UPDATE user SET `name` = ?, `email` = ?, `status` = ? where `ID` = ?");
mysqli_stmt_bind_param($stmt,'ssss', $this->name, $this->email, $this->status,$this->ID);

Use mysqli_affected_rows() to check number of rows affected by your update query!!