Now that we have pull information out of a database, now let's do something useful with it.
1. Create a new htm page, call it register.htm. This page will be used to let a user create a login and password so they can access your website.
2. Create a form & put as many fields as you want to collect information, but you must have the fields 'login' and 'password' . Write the code so you will be placing the form values into a database you will create in step 3. Make it look nice and use css to lay it out.
3. Create a new table in your Mysql database called login. Create the fields to match your form.
4. Run the register.htm page at least once to populate the database.
5. Create a new page, call it check_login.php. Put this code into the page (tweak this to fit your database & field names)
<?php
//connect to the server
$conn=mysql_connect("localhost", "add", "coyote");
//Select database to use
mysql_select_db("add");
//create sql string
$sql="SELECT * FROM login WHERE login='$_POST[login]' and password = '$_POST[password]'";
$result=mysql_query($sql, $conn) or dir(mysql_error());
//Count the number of rows in the database that has the correct data in it
$number_of_rows=mysql_num_rows($result);
// If result matched login and password, table row must be 1 row
if($number_of_rows==1){
// Register $myusername and redirect to file "login_success.php"
session_register("myusername");
header("location:login_successful.php");
}
else {
echo "Wrong Username or Password";
}
?>