4

im trying to get some data from my DB using this code:

<?php

error_reporting(E_ALL);
ini_set('display_errors',1);


$mysqli2 = new mysqli(********************);

    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
   }

    $sql2 = "SELECT message FROM wall_workouts_names WHERE id = ? ";

    $stmt2 = $mysqli2->prepare($sql2) or trigger_error($mysqli2->error."[$sql2]");

    $id_for_wall = '43';

    $stmt2->bind_param('s', $id_for_wall);

    $stmt2->execute();

    $stmt2->bind_result($message);

    $stmt2->store_result();

    $stmt2->fetch();

        echo $message;

?>

My problem is that i get empty string in my echo.

But if i run the same query in my phpmyadmin i get good results.

Thanks for helping

2
  • 1
    Although this question is a sure too localized one, +1 for having error reporting almost proper. Commented Sep 9, 2013 at 13:20
  • To make it straight: your code looks all right. As much as a human can tell. To investigate a problem you have to run your code and debug it. The sooner you understand it the sooner you have your code working. Commented Sep 9, 2013 at 14:01

2 Answers 2

1

Most likely there are no row to match condition in your WHERE clause, namely with id = 43

Sign up to request clarification or add additional context in comments.

7 Comments

Try to run it right here with a hardcoded (not bound) value and see. Using query()/fetch_array()
I tried hardcoded and i get empty result. But when i use it in my phpadmin, same query, i get good result...
WEll, you are querying another database with your phpmyadmin then
Its not, im sure about it.
You'd better trust your eyes, not speculations. This is a most important skill a developer have to develop. Try to select all the records from the table and see.
|
-1

Check your incoming results like this.

 while ($stmt->fetch()) {
   echo $message;    
 }

1 Comment

this code is useless itself and won't help to solve the particular problem in question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.