rookie2005 rookie2005 - 1 year ago 72
MySQL Question

Display profile data from database when login

I'm pretty much a beginner to php since I've shift. My registration is working fine and log in(checking if its in the database). I'm getting confused on using the session(display user who's logged in).

This is my login.php: (working fine)

$Regusername = $_POST['username'];
$Regpassword = $_POST['password'];

$dbc = @mysql_connect('localhost' , 'root','');
@mysql_select_db('market', $dbc);

$query1 = "SELECT username FROM customer WHERE password='$Regpassword' and username='$Regusername'";

$r1 = @mysql_query($query1, $dbc); // user
$row1 = mysql_fetch_array($r1); //

if ($row1['username'] == $Regusername && $Regpassword) {
Header("Location: home.php");
{ print '<p> <h1> Ooops, error login, please try again. </h1></p>'; }

then in my profile.php. At the top I've already added "$link = mysql_connect('localhost', 'root', '');"

session_start(); // Start Session Data
$username = $_SESSION['username'];

<?php echo "Name: ".$_SESSION['username']."" ; ?> //Undefined index: username in this line, the error shows up.

t only displays Name:
Hope somebody helps me of what am I missing or should change here.
Thank you so much in advance.

Answer Source

you never set the session:

$_SESSION['username']==$row1['username']; // is the same as 1=1 = true

that is a logical "query" meaning that session is row = true. however, it is supposed to be a statement where you set session to equal row. remove one of the equal signs.

also, this line looks rather confusing

if ($row1['username'] == $Regusername && $Regpassword)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download