Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting an Error when Retrieving the Data from the database PHP

(UPDATED)

I’m working on a personal project where the user’s data (user who log in) will be shown/fetch. When I run the PHP code, it does not give the error but also did not display or retrieve the data from the database, I dont know what part of the code is the problem. Should I need first declare the variables?

I also encounter an error that point the ’email’ in the query

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Notice: Undefined variable: email

This is the code so you can check.

<?php
    $query=mysqli_query($con,"SELECT * FROM tbl_account where email='$email' ");
    while($result = mysqli_fetch_array($query))
    {
        $email = $result['email'];  
        echo " <div class='info-user'>";
        echo " <div>";
        echo " <label>Firstname:</label>&nbsp;&nbsp;&nbsp;<b>".$result['firstName']."</b>";
        echo "</div> ";
        echo "<hr /> ";     
        echo "<br /> ";     
        echo " <div>";
        echo " <label>Lastname:</label>&nbsp;&nbsp;&nbsp;&nbsp;<b>".$result['lastName']."</b>";
        echo "</div> ";
        echo "<hr /> "; 
        echo "<br /> ";     
        echo " <div>";
        echo " <label>Username:</label>&nbsp;&nbsp;&nbsp;<b>".$result['email']."</b>";
        echo "</div> ";
        echo "<hr /> "; 
        echo "<br /> ";     
        echo " <div>";
        echo " <label>Username:</label>&nbsp;&nbsp;&nbsp;<b>".$result['sex']."</b>";
                    
    
        }
    ?>

EDIT. I already put the $email = $result['email'];above the query but it gave a new errors

Notice: Undefined variable: result
Notice: Trying to access array offset on value of type null

>Solution :

On this line:

    $query=mysqli_query($con,"SELECT * FROM tbl_account where email='$email' ");

$email is a variable. This variable has not been defined. That is why you get the error.

When you do define it (hard code it, or get it from somewhere), the error will disappear.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading