我是PHP OOP的新手,所以这个问题必须非常愚蠢。 我无法通过PHP创建SQL查询。我已多次阅读该代码,但我无法找到任何差异,甚至编辑器也没有显示任何错误。我使用的是PHP 5.5.13,MYSQL 5.5.24和APCHE Server 2.2.22。
以下是代码:
Test_signup.php
<!DOCTYPE HTML>
<html>
<head>
<title>
Test Sign Up
</title>
</head>
<body>
<form action = "Signup.php" method = "POST" name = "test_signup">
Full Name: <input type = "text" name = 'full_name'>
User Name: <input type = 'text' name = 'user_name'>
Email: <input type = 'text' name = 'email_add'>
<input type = "submit" name = "submit">
</form>
</body>
</html>
现在进入 Signup.php
<?php
$con = new mysqli('localhost', 'root', '', 'my_database');
if ($con->connect_error)
{
echo 'Failed to connect' . $con->connect_error;
}
else
{
echo 'Connected';
$stmt_chk_email = $con->prepare('SELECT * FROM `user_information` WHERE `Email` = ?');
$stmt_chk_email->bind_param('s', $_POST['email_add']);
echo $stmt_chk_email;
?>
尝试运行此代码时,我收到错误:
类mysqli_stmt的对象无法转换为字符串
当然原始查询比这里发布的要大得多。我已经编辑了查询的后面部分,因为我发现问题存在于SQL“SELECT”语句中,但我无法弄明白。请帮助我。 谢谢。
答案 0 :(得分:2)
你不能回应这个
echo $ stmt_chk_email;
你可能想要回应这个
$stmt_chk_email = $con->prepare('SELECT column1 ,column2,... FROM `user_information` WHERE `Email` = ?');
$stmt_chk_email->execute();
$stmt_chk_email->store_result();
$stmt_chk_email->bind_result($column1 ,$column2,.....);
$stmt_chk_email->fetch();
echo $column1;
echo $column2 ;
.....
答案 1 :(得分:0)
$stmt_chk_email = $con->prepare('SELECT `column` FROM `user_information` WHERE `Email` = ?');
$stmt_chk_email->bind_param('s', $_POST['email_add']);
$stmt_chk_email->execute();
$stmt_chk_emeil->store_result();
$stmt_chk_email->bind_result($check_email);
$stmt_chk_email->fetch();
echo $check_email;
OR
$stmt_chk_email = $con->prepare('SELECT * FROM `user_information` WHERE `Email` = ?');
$stmt_chk_email->bind_param('s', $_POST['email_add']);
$stmt_chk_email->execute();
$result = $stmt_chk_email->get_result();
if($result->num_rows == 1)
{
$result = $result->fetch_array();
echo $result['column_name'];
}