L Posted June 27, 2007 Share Posted June 27, 2007 Hello, I am having problems with making the login form disappear when a user logins. I want it so when the user session is registered, links, and a login text will display instead of the form. Here is my code <?php session_start(); if (ISSET($_POST['sublogin'])) { // Recreation of variables for later encryption uses the $_POST will be replaced with the decrypted source $username = trim($_POST['username']); $password = trim($_POST['password']); $cryptpassword = md5($password); $url = 'cp.php?user=$_SESSION[username]'; //Connects to DB require("database.php"); $table = "users"; $sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'"; $result = mysql_query($sql)or die(mysql_error()); // If result matched $myusername and $mypassword, table row must be 1 row if(mysql_num_rows($result) > 0) { // Registers sesions and redirect to file "login_success.php" $storage = mysql_fetch_assoc($result); //Sessions here $_SESSION['username'] = $storage['username']; $_SESSION['userid'] = $storage['userID']; header("location: $url"); echo "Logged In<br />"; echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <br><br>" ."<a href=\"cp.php?user=$_SESSION[username]\">My Account</a><br /> "; echo "<a href=\"logout.php\">Logout</a>"; } else{ } else { echo "Wrong Username or Password"; } } ?> <form action="" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30"/></td></tr> <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30"></td></tr><tr><td> <input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr> </table> </form> Thank you for your time, ~L Quote Link to comment Share on other sites More sharing options...
Caesar Posted June 27, 2007 Share Posted June 27, 2007 <?php if((!isset($_SESSION['username'])) | (!isset($_SESSION['userid']))) { echo' <form action="" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30" /></td></tr> <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30" /></td></tr> <tr><td><input type="submit" name="sublogin" value="Login" /></td></tr> </table> </form>'; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 27, 2007 Share Posted June 27, 2007 should it be two || <<<<<<<<<< dont no? Quote Link to comment Share on other sites More sharing options...
L Posted June 27, 2007 Author Share Posted June 27, 2007 hmm...it's not working...now the form isn't showing up when im not logged in. here's the code <?php session_start(); if (ISSET($_POST['sublogin'])) { // Recreation of variables for later encryption uses the $_POST will be replaced with the decrypted source $username = trim($_POST['username']); $password = trim($_POST['password']); $cryptpassword = md5($password); $url = '/cp.php?user=$_SESSION[username]'; //Connects to DB require("database.php"); $table = "users"; $sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'"; $result = mysql_query($sql)or die(mysql_error()); // If result matched $myusername and $mypassword, table row must be 1 row if(mysql_num_rows($result) > 0) { // Registers sesions and redirect to file "login_success.php" $storage = mysql_fetch_assoc($result); //Sessions here $_SESSION['username'] = $storage['username']; $_SESSION['userid'] = $storage['userID']; header("location: $url"); } else { echo "Wrong Username or Password"; } } if((!isset($_SESSION['username'])) || (!isset($_SESSION['userid']))) { echo' <form action="" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30" /></td></tr> <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30" /></td></tr> <tr><td><input type="submit" name="sublogin" value="Login" /></td></tr> </table> </form>'; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 27, 2007 Share Posted June 27, 2007 <?php session_start(); if (ISSET($_POST['sublogin'])) { // Recreation of variables for later encryption uses the $_POST will be replaced with the decrypted source $username = trim($_POST['username']); $password = trim($_POST['password']); $cryptpassword = md5($password); $url = '/cp.php?user=$_SESSION[username]'; //Connects to DB require("database.php"); $table = "users"; $sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'"; $result = mysql_query($sql)or die(mysql_error()); // If result matched $myusername and $mypassword, table row must be 1 row if(mysql_num_rows($result) > 0) { // Registers sesions and redirect to file "login_success.php" $storage = mysql_fetch_assoc($result); //Sessions here $_SESSION['username'] = $storage['username']; $_SESSION['userid'] = $storage['userID']; header("location: $url"); } else { echo "Wrong Username or Password"; } } if((empty($_SESSION['username'])) || (empty($_SESSION['userid']))) { echo' <form action="" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30" /></td></tr> <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30" /></td></tr> <tr><td><input type="submit" name="sublogin" value="Login" /></td></tr> </table> </form>'; } ?> Quote Link to comment Share on other sites More sharing options...
L Posted June 27, 2007 Author Share Posted June 27, 2007 sweet thnx for the help Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 27, 2007 Share Posted June 27, 2007 Ok m8 hit solved if it is solved cheers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.