Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

php - Catchable fatal error: Object of class mysqli_stmt could not be converted to string

I'm new to PHP OOP so this question must be quite dumb. I'm unable to create an SQL query through PHP. I've read the code many times but I'm unable to find any discrepancy and even the editor isn't displaying any error. I'm using PHP 5.5.13, MYSQL 5.5.24 and APCHE Server 2.2.22.

Following is the code:

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>

Now coming to the 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;
?>

When trying to run this code, I'm receiving an error:

Object of class mysqli_stmt could not be converted to string

Of course the original query is much larger than posted here. I've edited the later part of the query as I figured out that the problem resides within the SQL "SELECT" statement but I'm unable to figure it out. Kindly help me on this. Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you cant echo this

echo $stmt_chk_email;

you maybe want to echo this

     $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 ;
  .....

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...