0

this is my validation page

 <html>
    <body>
    <?php
    function error_found(){
      header("Location: login.php");
    }
    set_error_handler('error_found');
    ?>
    <?php
    $con=mysqli_connect('localhost','root','','mydb');
    session_start();
    if(isset($_POST['loginbtn'])){
    $email=$_POST['email'];
    $password=$_POST['pwd'];
    $result=mysqli_query($con,'select * from myguests where email="'.$email.'" and password="'.$password.'"');
    if(mysqli_num_rows($result)==1)
    {
        $_SESSION['email']= $email;
        header("Location: welcome.php");
    }
    else
        echo"INVALID ACCOUNT";

    }

    ?>

    </body>
    </html>

this is my user profile page

<html>
    <body>

    <?php    
     require_once 'valid.php'; 
        session_start();    
    echo"welcome  " .$_SESSION['email'];
    $res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email=".$_SESSION['email']);
     $userRow=mysqli_fetch_array($res);
     echo $userRow;
    ?>
    <br><a href="logout.php">logout</a>
    </body>
    </html>

>

I am not able to fetch the data from the database it shows me the error.I think I made mistake in declaring a session variable to the SQL query

1
  • you forgot to put $_SESSION['email'] in single quotes in select query. Commented Dec 5, 2017 at 6:24

2 Answers 2

2

You have an error on your sql.

$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email=".$_SESSION['email']);

It should be:

$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."');

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

Comments

0

You have an error in commented line check.

$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."'"); // this line has an issue with "'" 


<html>
    <body>

    <?php    
     require_once 'valid.php'; 
        session_start();    
    echo"welcome  " .$_SESSION['email'];
    $res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."'"); // Missing "'" in query to enclosed parameter.
     $userRow=mysqli_fetch_array($res);
     echo $userRow;
    ?>
    <br><a href="logout.php">logout</a>
    </body>
    </html>

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.