adamjones Posted November 8, 2008 Share Posted November 8, 2008 Ok. So I have a login form, and its posting to this page, where it checks the user and pass, and then registers sessions, etc; <?php ob_start(); $host="localhost"; $username="wowdream_molten"; $password="password"; $db_name="wowdream_molten"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $data=mysql_fetch_array($result); $access= $data['access']; $id= $data['id']; $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("access"); session_register("mypassword"); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $lastlogin = $data['lastlogin']; session_register("lastlogin"); $DB_Query = @mysql_query("UPDATE `members` SET lastlogin=Now() WHERE username='$myusername'") OR die('MySQL error: '.mysql_error()); header("location:community.php"); } else { header("location:loginerror.php"); } ob_end_flush(); ?> Just wondering how to make it redirect to an error page, if the username is already registered in the database? Regards. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 You need to use header() to redirect but you can't have anything sent to the browser before you use this. if (!empty($username)) { header("Location: alreadyexists.php"); exit; } Something like that. Quote Link to comment Share on other sites More sharing options...
BoltZ Posted November 8, 2008 Share Posted November 8, 2008 if(isset($username)) { //redirect } 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.