Page 1 of 1
How do I create A register file and login file
Posted: Fri Apr 08, 2005 4:17 am
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
Posted: Fri Apr 08, 2005 8:00 am
by Chris Corbyn
Please do not cross-post

Re: How do I create A register file and login file
Posted: Fri Apr 08, 2005 10:47 am
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("e;SELECT id WHERE user='$user' and pass='$pass'"e;)
or die ('error: ' . mysql_error());
$row = mysql_fetch_array($result);
$id = $rowї'id'];
if (!$id) //incorrect login
{
$message = "e;Whoops! Wrong login info."e;;
}
else
{
$_SESSIONї'id'] = $id;
header("e;Location: regular.php"e;);
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("e;Location: login.php"e;);
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
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]