Jump to content

Just a question about my login form


adamjones

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/131919-just-a-question-about-my-login-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.