i am my function is unable to use where condition in my function when i want to update appropriate user_id like this: where user_id= ?
look at my function :
public function createProfile($profile_picture, $username,$businessname, $town) {
$stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
$stmt->bind_param("ssss",$profile_picture, $username,$businessname, $town);
$stmt->execute();
}
his the way i am calling createProfile function to let update
<?php
include './DbHandler.php';
$db = new DbHandler();
$response = array();
if ( ( isset($_POST['profile_picture']) && isset($_POST['username']) && isset($_POST['businessname']) && isset($_POST['town']) )!= '') {
$profile_picture = $_POST['profile_picture'];
$username = $_POST['username'];
$businessname = $_POST['businessname'];
$town = $_POST['town'];
$res = $db->createProfile($profile_picture, $username,$businessname);
}
?>
As you have five placeholders ( ?
) = you should pass 5 parameters to bind_param
. Easy way to do this is pass $user_id
as an argument:
public function createProfile($profile_picture, $username,$businessname, $town, $user_id) { // user_id is a five parameter here
$stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
// I suppose user_id has is `integer` type
$stmt->bind_param("ssssi",$profile_picture, $username, $businessname, $town, $user_id);
$stmt->execute();
}
As we don't know what is there in your class - maybe user id is somewhere in class properties (named user_id
in my example), then you can use it like this:
public function createProfile($profile_picture, $username,$businessname, $town) { // NO user_id passed
$stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
// I suppose user_id has is `integer` type
$stmt->bind_param("ssssi",$profile_picture, $username, $businessname, $town, $this->user_id);
$stmt->execute();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.