DbOperations.php
public function getGender($id)
{
$stmt = $this->con->prepare("select gender, dob_year from table_user where id = '$id'");
$stmt->bind_param("ss", $gender, $dob_year);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}
data.php
<?php
require_once 'database_config/DbOperations.php';
$response = array();
$id = $_POST['id'];
$db = new DbOperations();
$user = $db->getGender($id);
$response['gender'] = $user['gender'];
$response['dob_year'] = $user['dob_year'];
echo json_encode($response);
?>
嗨,我正试图从&#34; id&#34;中获取dob_year和性别信息。输入。但它会发出警告
mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
可能是什么原因?
答案 0 :(得分:0)
应该是这样的
public function getGender($id)
{
$stmt = $this->con->prepare("select gender, dob_year from table_user where id = ?");
$stmt->bind_param("s",$id);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}