SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP printing double

    After someone registers & logs in I want to print out an array of their user values,
    I finally got it to do just that, but now it's printing them twice... I've included the PHP for review,
    but you may have to register and login to see the actual effect live. I just can't figure out why it's
    printing everything from the $row = $_SESSION['Row']; twice!

    http://buffetburger.com/

    Code:
    <?php include "base.php"; ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>User Management System (Tom Cameron for NetTuts)</title>
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>  
    <body>  
    <div id="main">
    <?php
    if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
    {
    	 ?>
        
        <h1>Member Area</h1>
      	 <p>Thanks for logging in! You are <b><?=$_SESSION['Username']?><b> and your email address is <b><?=$_SESSION['EmailAddress']?></b>.</p>
        
        <ul>
            <li><a href="logout.php">Logout.</a></li>
        </ul>
    <?php
    
    $row = $_SESSION['Row'];
    
       foreach ($row as $name => $value){
        print "$value <br />\n";
      } // end foreach
    ?>
        <?php
    }
    elseif(!empty($_POST['username']) && !empty($_POST['password']))
    {
    	 $username = mysql_real_escape_string($_POST['username']);
        $password = md5(mysql_real_escape_string($_POST['password']));
        
    	 $checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."'");
        
        if(mysql_num_rows($checklogin) == 1)
        {
        	 $row = mysql_fetch_array($checklogin);
            $email = $row['emailaddress'];
            
            //$email = $row['emailaddress'];
            //$_SESSION['EmailAddress'] = $email;
            
            $_SESSION['Username'] = $username;
            $_SESSION['EmailAddress'] = $email;
            $_SESSION['LoggedIn'] = 1;
    		$_SESSION['Row'] = $row;
    		
            
        	 echo "<h1>Success</h1>";
            echo "<p>We are now redirecting you to the member area.</p>";
            echo "<meta http-equiv='refresh' content='2;index.php' />";
        }
        else
        {
        	 echo "<h1>Error</h1>";
            echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>";
        }
    }
    else
    {
    	?>
        
       <h1>Member Login</h1>
        
       <p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>
        
    	<form method="post" action="index.php" name="loginform" id="loginform">
    	<fieldset>
    		<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
    		<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
    		<input type="submit" name="login" id="login" value="Login" />
    	</fieldset>
    	</form>
        
       <?php
    }
    ?>
    </div>
    </body>
    </html>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You don't need to use a foreach loop to do what you can by simply using print_r and some <pre> tags, see the below example:

    PHP Code:
    echo '<pre>';
    print_r($_SESSION['Row']);
    echo 
    '</pre>'
    Off Topic:

    Needs to be moved to the PHP forum

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by chris.upjohn View Post
    Off Topic:

    Needs to be moved to the PHP forum
    Off Topic:

    Moved. For these kind of requests you can click the report icon (the little red flag) to the left of each post.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •