How do I create A register file and login file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Arsenal Rule
Forum Commoner
Posts: 26
Joined: Fri Apr 08, 2005 4:13 am

How do I create A register file and login file

Post by Arsenal Rule »

Basically I'm new to PHP I have trie reading relative book but still I really don't understand how it works. I'm just asking if anyone can help me. Well I have a MySql database and in the database is a password table that have the fields: User ID "Auto-Increment", firstname, surname, username and password. So my problem is that I need to create a register file that will allow the user to register and enter their details and it will store in the password table of the database. Then after that I need to create a login file that will ask the user to enter there username and password and then it will check if the username and password is stored in the databse, and if it is not in the database it will give an error message that will ask them to type it in again, and if it is in the database it will allow them to go the next page which is regular.php.

I really hope someone can help me with this I would be so greatful thankyou so much for your time
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Please do not cross-post :!:
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: How do I create A register file and login file

Post by Jade »

Arsenal Rule wrote:Basically I'm new to PHP I have trie reading relative book but still I really don't understand how it works. I'm just asking if anyone can help me. Well I have a MySql database and in the database is a password table that have the fields: User ID "Auto-Increment", firstname, surname, username and password. So my problem is that I need to create a register file that will allow the user to register and enter their details and it will store in the password table of the database. Then after that I need to create a login file that will ask the user to enter there username and password and then it will check if the username and password is stored in the databse, and if it is not in the database it will give an error message that will ask them to type it in again, and if it is in the database it will allow them to go the next page which is regular.php.

I really hope someone can help me with this I would be so greatful thankyou so much for your time
Hey there,

First of all here's a general idea of what you need to do to make something like this work. You don't need a text file to check a username/password against the database. Here's the basic idea of a login:

Code: Select all

<?php
session_start();

$user = $_GETї'user'];
$pass = $_GETї'pass'];

if ($user && $pass)
{
//connect to the database
include('../dbconnect.php');

$result = mysql_query(&quote;SELECT id WHERE user='$user' and pass='$pass'&quote;)
or die ('error: ' . mysql_error());

$row = mysql_fetch_array($result);
$id = $rowї'id'];

if (!$id) //incorrect login
{
$message = &quote;Whoops! Wrong login info.&quote;;
}
else
{
$_SESSIONї'id'] = $id;
header(&quote;Location: regular.php&quote;);
exit;
}
?>
<html>
<body>
<?php if ($message) echo $message; ?>
<form action=# method=post>
User: <input type=text name=user><br><br>
Pass: <input type=password name=pass><br><br>
<input type=submit value=Submit>
</form>
</body>
</html>

Code: Select all

<?php
session_start();

if (!$_SESSIONї'id']) //session has ended, or not logged in
{
header(&quote;Location: login.php&quote;);
exit;
}

//include database login
include('../dbconnect.php');

//the rest of your code here

?>

I think you get the idea....


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply