-2

I have a Login script that is on my home page for my Login form that is also on my home page. When the user submits the form to Login he/she submits his/her username and password.

The database that the script accesses has the Username, Password, and Email Address stored from the users registration.

Once the user logs in successfully, he/she is redirected to a page that loads their previous "reviews" on the page which are stored within a different table within the same database.

I need to send the email from one table to the query on the redirected page.

Here is the code of my PHP code that processes the Login:

<?php

//If the user has submitted the form
if(isset($_REQUEST['username'])){
    //protect the posted value then store them to variables
    $username = protect($_POST['username']);
    $password = protect($_POST['password']);

    //Check if the username or password boxes were not filled in
    if(!$username || !$password){
        //if not display an error message
        echo "<center>You need to fill in a <b>Username</b> and a <b>Password</b>!</center>";
    }else{
        //if they were continue checking

        //select all rows from the table where the username matches the one entered by the user
        $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
        $num = mysql_num_rows($res);

        //check if there was no match
        if($num == 0){
            //if none, display an error message
            echo "<center>The <b>Username</b> you supplied does not exist!</center>";
        }else{
            //if there was a match continue checking

            //select all rows where the username and password match the ones submitted by the user
            $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."'");
            $num = mysql_num_rows($res);

            //check if there was no match
            if($num == 0){
                //if none display error message
                echo "<center>The <b>Password</b> you supplied does not match the one for that username!</center>";
            }else{
                //if there was continue checking

                //split all fields from the correct row into an associative array
                $row = mysql_fetch_assoc($res);

                //check to see if the user has not activated their account yet
                if($row['active'] != 1){
                    //if not display error message
                    echo "<center>You have not yet <b>Activated</b> your account!</center>";
                }else{
                    //if they have log them in

                    //set the login session storing there id - we use this to see if they are logged in or not
                    $_SESSION['uid'] = $row['id'];


                    //update the online field to 50 seconds into the future
                    $time = date('U')+50;
                    mysql_query("UPDATE `users` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");

                    //redirect them to the usersonline page
                    echo 'REDIRECT';

                }
            }
        }
    }

    exit;
}

?>

Here is the PHP Code that is on the Re-directed to page:

<?php
  $con=mysqli_connect("","","","");
  // Check connection
  if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  $result = mysqli_query($con,"SELECT * FROM comments
    WHERE email='$_POST[email]' ORDER BY dt");

  while($row = mysqli_fetch_array($result))
  {
    echo $row['dt'] ." " . $row['email'] . " " . $row['body'];
    echo "<br>";
    echo "<br>";
  }
?>

I need to add something to the first code to pick up the email address out of the table it uses to verify the Login information and send it to the second code to receive the "reviews." I have tried googling an answer and came up with nothing. Please help!

Nick Andriopoulos
  • 10,313
  • 6
  • 32
  • 56
user2109152
  • 67
  • 1
  • 2
  • 9

1 Answers1

0

Since you have used the $_SESSION array in your code(which maybe is copied from somewhere), you can similarly store the email address in the same array.

$_SESSION['email'] = $row['email'];

In the later page, you'd need to replace $_POST['email'] with $_SESSION['email'].

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • I placed this code into my script that processes the Login information. The reviews still do not appear in the logged in screen. Did I put the code in the wrong spot? – user2109152 Mar 28 '13 at 07:23
  • 1
    `email='$_POST[email]'` in your redirected code also needs the `$_SESSION` instead of `$_POST` – bart s Mar 28 '13 at 07:25