Echoing SQL Statement Thorugh PHP

Discussion in 'PHP' started by saadi123, Feb 8, 2014.

  1. #1
    I've been trying to echo the output of SQL SELECT statement but an error keeps displaying which says:
    The code is mentioned below:
    
    $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']);
            $stmt_chk_email->execute();
            echo $stmt_chk_email;
    }
    
    Code (markup):
    Obviously, I don't want to just echo the SQL query. I haven't mentioned the later part of the code because I wanted to see that what part of the code is erroneous by echoing the result. So it seems like that the query is not running at all. I've checked the syntax and it seems to be quite fine. My editor is also not displaying any error so its obvious that the logic is flawed.
    I'd appreciate if someone figures that one out.
    Thanks.
     
    saadi123, Feb 8, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Use print_r instead of echo.
     
    PoPSiCLe, Feb 8, 2014 IP
  3. Dadabing

    Dadabing Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #3
    I think you getting array as result. it means you have either print_r it, or echo exact key from array like this:
    echo $stmt_chk_email[0];
    however firstly do print_r then youll be able to see whole array output and determine what do you want to echo exactly. Las thing would be simply foreach $stmt_chk_email to see what it outputs like this:
    foreach ($stmt_chk_email as $key => $item){
    echo $item[$key];
    }
     
    Dadabing, Feb 17, 2014 IP
  4. saadi123

    saadi123 Well-Known Member

    Messages:
    196
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    saadi123, Feb 17, 2014 IP