0

im trying to get data from my DB but all i get is null values.

I know that the query isnt empty because i get values from inside my if($stmt->num_rows > 0)

code.

When i run my query on my phpmyadmin i also get good results.

This is my code thanks for helping:

$sql = "SELECT register_date FROM personal WHERE user_id = ?"; 

    $stmt = $mysqli->prepare($sql) or trigger_error($mysqli->error."[$sql]");

    $stmt->bind_param('s', $user_id);

    $user_id = $_GET['user_id'];

    $stmt->execute();

    $stmt->store_result();

    $stmt->bind_result($register_date);

    if($stmt->num_rows > 0)
    {

         $response["date"] = $register_date;
         $response["success"] = 1;
           // echoing JSON response
           echo json_encode($response);

    }

    else
    {
          $response["success"] = 0;
          echo json_encode($response);
    }
4
  • Still can't get your code to work?.. Commented Aug 1, 2013 at 8:54
  • Not familiar with MySQLi but don't you need to set $user_id before the bind_param? Commented Aug 1, 2013 at 9:04
  • Besides fetch, you need also to close the statement. Commented Aug 1, 2013 at 9:10
  • @AlexP this one is absolutely unnecessary Commented Aug 1, 2013 at 9:31

2 Answers 2

2

Try

$stmt->bind_result($register_date);
$stmt->execute();
$stmt->store_result();
$stmt->fetch();
echo $register_date;

Please read bind_result doc

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

1 Comment

I forgot about $stmt->fetch();. Thank you for helping
-1

Your code is a bit mixed up, you'll need to define your variables (in this case $user_id) before using them.

I suggest moving to PDO rather than using MySQLi.

Comments

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.