Try using soemthing like the following
register.php
PHP Code:
<?
if($_POST['action']=="register")
{
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
msql_select_db('database',$link);
$query = "INSERT INTO member (username,password)VALUES('{$_POST['username']}','" . md5($_POST['password']). "')"; //create the new user
mysql_query($query,$link);
?>
Thank you for registering <?=$_POST['username']?>. You can now login.
<?
}
else
{
?>
<form method="post">
<table class="columns" cellspacing="0" cellpadding="0">
<tr>
<th class="column">Login</th>
</tr>
<tr>
<td>Username
<input type="text" name="username" class="text"/>
</td>
</tr>
<tr>
<td>Password
<input type="password" name="password" class="text"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="action" value="reg" />
<input type="submit" name="submit" value="Register" class="button" />
</td>
</tr>
</table>
</form>
<?
}
?>
checklogin.php
PHP Code:
<?
session_start();
function check_user_and_password($username,$password)
{
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
msql_select_db('database',$link);
$query = "SELECT username,password FROM member WHERE username = '$username' AND password = '" . md5($password) . "'";
mysql_query($query,$link);
if(!empty($results)) //if the query returns nothing then they havent logged in correctly
{
$_SESSION['username'] = $username; //set a value to check later
$_SESSION['loggedin'] = true;
return true;
}
else
{
return false;
}
}
?>
yourscript.php
PHP Code:
<?
require_once('checklogin.php');
if($_SESSION['loggedin'] == true) //check tosee if they are already logged in
{ //display the memeber stuff
?>
Your memeber stuff here!
<?
}
else
{
if($_POST['action'] == "login") // check to see if they are trying to login
{
check_user_and_password($_POST['username'],$_POST['password']);
header('Location: ' $_SERVER['PHP_SELF']); //refresh so user sees member section
}
else // they are not tryin to login so make them
{
?>
<form method="post">
<table class="columns" cellspacing="0" cellpadding="0">
<tr>
<th class="column">Login</th>
</tr>
<tr>
<td>Username
<input type="text" name="username" class="text"/>
</td>
</tr>
<tr>
<td>Password
<input type="password" name="password" class="text" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="action" value="login" />
<input type="submit" name="submit" value="Login" class="button" />
</td>
</tr>
</table>
</form>
<?
}
}
?>
It is really basic but it will get you started on what you want to do.