stmt prepare me nothing appears to me

Asked

Viewed 29 times

0

I have this code to print the data on the page coming from the database:

<?php

    session_start();
    include "conection.php";

    $id_login = $_SESSION["id_login"];

    $stmt =$db->prepare("select login.username, login.nome, login.id_login from login where login.id_login=?");

    $stmt->bind_param('i',$id_login);
    $stmt->execute();
    $stmt->bind_result($username,$nome,$id_login);
    $stmt->fetch();
    $stmt->close();
?>

I already tested the query and it’s fine. It also returns the session variable $id_login. But the page goes blank and I can’t see what the mistake is. Thank you.

  • Put this at the top of the page, ini_set('display_errors', true); error_reporting(E_ALL); blank page is already a mistake.

  • 1

    Without any echo, print, var_dump or printf the page will go blank even

1 answer

0

The code doesn’t look wrong, but there’s nothing to print on it. Try this way:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();

$db= new mysqli("host", "user", "password", "database");

if (mysqli_connect_errno()) {
    echo "Error: ".mysqli_connect_error();
    exit();
}


if ($stmt = $db->prepare("SELECT login.username, login.nome, login.id_login FROM login WHERE login.id_login = ?")) {

    $stmt->bind_param('i', $id_login);
    $id_login = $_SESSION["id_login"];

    $stmt->execute();
    $stmt->bind_result($username, $nome, $id_login); // deve ter o mesmo número de variáveis e colunas na tabela

    while ($stmt->fetch()) {
        echo $username."|".$nome."|".$id_login."<br/>";
    }
    $stmt->close();
}

$db->close();

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.