我正在制作一个登录表单,我对如何使用绑定参数选择数据感到困惑。
我目前的代码如下:
$stmt = $mysqli_conn->query('SELECT * FROM user WHERE email = ? AND password = ?');
$stmt->bind_param('ss', $emailclean, $passwordclean);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
$finalmessager['success'] = 'You are logged in';
$_SESSION['finalmessagelog']= $finalmessager;
$_SESSION['authenticateduser']= $emailclean;
header('location:../index.php');
unset($_SESSION['logErrors']);
}
我不明白为什么这不起作用
答案 0 :(得分:0)
我举一个例子:
<?php
$query = "SELECT * FROM user WHERE email = ? AND password = ?";
$stmt = $this->db->prepare($query);
$stmt ->bind_param("ss", $emailclean, $passwordclean); //both are strings
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($column1, $column2); //you have to assign every column
while($stmt->fetch())
{
if($column1 == 1){ //first column is id? just guessing
echo "its the id 1 yeah!";
}
echo "col1: $column1, col2: $column2 \n";
}
$stmt->close();