dasdasd
dasdasd

Reputation: 2031

mysqli returning null values

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);
    }

Upvotes: 0

Views: 1422

Answers (2)

ujjwalwahi
ujjwalwahi

Reputation: 342

Try

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

Please read bind_result doc

Upvotes: 2

Story Teller
Story Teller

Reputation: 427

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.

Upvotes: -1

Related Questions