我正在尝试执行准备好的SELECT
查询,并且在准备好的部分失败并出现此错误...
Admin Help Email SELECT prepare() failed: Operand should contain 1 column(s)
我基本上理解,但我不知道如何改变它来做我想要完成的事情。我正在尝试SELECT
来自users表的id,其中id是用户的会话ID。然后SELECT
我尝试选择的所有其他字段而不是全部。我被告知,无论是个人多次,这是更好的练习,所以我试图以正确的方式做到这一点。
我怎样才能改变这一点,使其适用于我想要完成的任务?
$userid = ( isset( $_SESSION['user'] ) ? $_SESSION['user'] : "" );
$help_message = $_POST['help_message'];
$con = mysqli_connect("localhost", "", "", "");
$stmt = $con->prepare("SELECT(`id`, `firstname`, `lastname`, `email`, `phone_number`, `username`) FROM users WHERE id=?");
if ( !$stmt || $con->error ) {
// Check Errors for prepare
die('Admin Help Email SELECT prepare() failed: ' . htmlspecialchars($con->error));
}
if(!$stmt->bind_param('i', $userid)) {
// Check errors for binding parameters
die('Admin Help Email SELECT bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$stmt->execute()) {
die('Admin Help Email SELECT execute() failed: ' . htmlspecialchars($stmt->error));
}
while($row = mysqli_fetch_assoc($q)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
$phone_number = $row['phone_number'];
$username = $row['username'];
}
新代码
$con = mysqli_connect("localhost", "", "", "");
$stmt = $con->prepare("SELECT id, firstname, lastname, email, phone_number, username FROM users WHERE id=?");
if ( !$stmt || $con->error ) {
// Check Errors for prepare
die('Admin Help Email SELECT prepare() failed: ' . htmlspecialchars($con->error));
}
if(!$stmt->bind_param('i', $userid)) {
// Check errors for binding parameters
die('Admin Help Email SELECT bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$stmt->execute()) {
die('Admin Help Email SELECT execute() failed: ' . htmlspecialchars($stmt->error));
}
while($row = mysqli_fetch_assoc($stmt)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
$phone_number = $row['phone_number'];
$username = $row['username'];
}