I will assume that you already have some understanding of php, such as starting your php code with "<?php" and ending with "?>".
Enough already... let's get to it.
We will have 3 documents (form.php, process.php, and welcome.php).
Starting with form.php:
We need to have a form for the user to enter their username and password.
<form id="form1" name="form1" method="post" action="process.php">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="24%"> </td>
<td width="2%"> </td>
<td width="74%"> </td>
</tr>
<tr>
<td><div align="right"><strong>Username:</strong></div></td>
<td> </td>
<td><input name="un" type="text" id="un" /></td>
</tr>
<tr>
<td><div align="right"><strong>Password:</strong></div></td>
<td> </td>
<td><input name="pw" type="password" id="pw" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" />
<input name="Clear" type="reset" id="Clear" value="Clear" /></td>
</tr>
</table>
</form>
Now to check their username and password with process.php:
<?php
//create a session
session_start();
//database variables and connection
$host = "localhost";
$user = "username";
$pass = "password";
$dbase = "database";
$link = mysql_connect("$host","$user","$pass") or die ("Link Error");
$db_connect = mysql_select_db($dbase, $link) or die ("Database Connection Error.");
//form variables
$un = $_POST['un'];
$pw = $_POST['pw'];
//encrypt the password to match the md5 password in the database
//you can skip this if your password isn't encrypted with md5 or modify it to whatever you
//please
$pw = md5($pw);
// check the database
$query = "SELECT * FROM users WHERE username = '$un' and password = '$pw'";
$result = mysql_query($query, $link) or die("Unable to verify user because : " . mysql_error());
$row = mysql_num_rows($result);
$rs1 = mysql_fetch_assoc($result);
//give the session username the users username
$_SESSION['username'] = $rs1['username'];
//this is where the actual verification happens
if($row == 1){
header ("Location: welcome.php");
}else{
$err = 'Incorrect username / password.';
}
//then just above your login form or where ever you want
//the error to be displayed you just put in
echo $err;
mysql_close($link);
?>
Last part of welcome.php
<?php
session_start();
echo "Welcome ". $_SESSION['username'];
?>
[ add comment ] | permalink |




( 2.9 / 32 )This past weekend I went fishing at Red Run again. I caught around 15 native brooke trout. The weather was a little warm, but overall the conditions were pretty good in my opinion. I'd suggest taking a visit to the Canaan Loop Road to anyone interested in hiking, biking and fly fishing. West Virginia has beautiful country and great outdoor activities.
The Red Run Sign...

The Stream...

The biggest trout I've caught at Red Run (taken with camera phone)

[ add comment ] | permalink |




( 3 / 22 )http://www.wickedpissahgames.com/games/ ... yPods.html
There is a chance you may become addicting.
[ add comment ] | permalink |




( 3.2 / 25 )My order from Hill's Discount Flies came today. I was very impressed with the quality of the flies and the quickness of delivery.
I had a few moments while being bored with my Nikon D200 to try taking some photos. I soon realized the value of a macro lens. On the digital photography forums they talk about "lens lust" and quickly realized what they really meant.
Dave's Hopper - Bullet Head & Parachute

Copper John - Red

The photographs didn't come out bad, but they could of been better.
[ add comment ] | permalink |




( 2.9 / 29 )Today I went fly fishing for native brook trout off of the Canaan Loop Road at Red Run. It's amazing how fast time passes by when you're having fun. The trout were sucking the caddis flies off the top like crazy. It's a very small stream and the trout at their biggest were about six inches, but had beautiful colors.
[ add comment ] | permalink |




( 3.1 / 16 )Next
| 1 | 2 |

Calendar



