Hello. Im wanting to create a very simple login form. using HTML PHP and SQL (i use putty to input my SQL).
Basically all pages on my website apart from home page, login page, registration page can only be viewed if a user is logged on.
I want to create a very simple login form and registration from. So on the login form the user enters there username and password, the php checks the sql table 'users' (which contains ID (automatically generated) name, surname, username, password, year of birth, email address) to see if the username exists and matches the password.
On the registration page the user enters name, surname, year of birth, desired username password (twice which must match) desired password and email address. This information updates the users table and adds the information to it. I'm stumped on how to do this. any help is appreciated.
PS
I dont need help with the SQL just the php
thanks
simple log in form
Moderator: General Moderators
Re: simple log in form
Well, basically here's what your wanting to do.
You want to create a form in HTML first,
This is the form:
This would be the basic execution:
To check if the user is logged in, use this on the top of the page or something:
Ofcourse, this is a VERY basic code and alot can be added. One thing you should look into, is session ids, so no one can log you out etc.
You want to create a form in HTML first,
This is the form:
Code: Select all
<table>
<form action="login.php" method="post">
<tr><td>Username: </td><td><input type="text" name="username" /></td></tr>
<tr><td>Password: </td><td><input type="password" name="password" /></td></tr>
<tr><td></td><td><input type="submit" name="login" value="Login"></td></tr>
</form>
</table>
This would be the basic execution:
Code: Select all
<?php
//CONNECT TO MYSQL
$Posted_Username=$_POST['username'];
$Posted_Password=$_POST['password'];
$Stripped_Username = stripslashes($Posted_Username);
$Stripped_Password = stripslashes($Posted_Password);
//Just protecting the username and password.
$Username = mysql_real_escape_string($Stripped_Username);
$Password = mysql_real_escape_string($Stripped_Password);
$query = mysql_query("SELECT * FROM usertable WHERE username = '" . $Username . "' AND password = '" . $Password . "'");
$num_rows = mysql_num_rows($query);
if($num_rows == "1"){
$_SESSION['logged_in'] = "true";
$_SESSION['username'] = $Username;
$_SESSION['password'] = $Password;
header("location:login_success.php");
}
else{
echo "Wrong Username or Password";
}
?>
Code: Select all
<?php
if($_SESSION['logged_in'] == "true"){
//Run the page script
}
else{
echo 'not logged in';
}
Re: simple log in form
thanks alot
thats what i was looking for.
thats what i was looking for.