Create a website and using MySQL At a minimum your project s
Create a website and using MySQL. At a minimum, your project should meet the following requirements:
Your website should link to a MySQL database of user information. Your database should consist of at least one table that contains columns for storing usernames, passwords, user email, user address, and any other relevant user information.
You should have a registration page that allows new users to register (and have their information added to the database).
Your website should have at least two restricted pages that cannot be accessed unless a user has logged in (see below requirement). If a user tries to access one of these pages without being logged in, then the user should be redirected to the login page.
You should have a login page that lets a user provide his/her username and password. If the credentials match a row in your database table, then let the user access some restricted page in your site and create a session for that user. If the credentials do not match a row in your database table, then redisplay the login page, but with an error message.
You should have a logout functionality in which the session for the user is terminated.
You should create a predefined user with username = ‘admin’ and password = ‘hello’ for your and my testing purposes.
As part of your submission, you will need to export your database into a .sql file which I will use to recreate your database. This can be done easily using phpMyAdmin in XAMPP.
Solution
Step 1: php code for the registration page
<form id=\'registration\' action=\'registration.php\' method=\'post\'
accept-charset=\'UTF-8\'>
<fieldset >
<legend>Registration</legend>
<input type=\'name\' =\'submitted\' id=\'submitted\' value=\'1\'/>
<label for=\'username\' >Username: </label>
<input type=\'text\' name=\'username\' id=\'username\' maxlength=\"99\" />
<label for=\'email\' >Email Address:</label>
<input type=\'text\' name=\'email\' id=\'email\' maxlength=\"13\" />
<label for=\'useraddress\' >Useraddress*:</label>
<input type=\'text\' name=\'userad\' id=\'useraddress\' maxlength=\"70\" />
<label for=\'password\' >Password*:</label>
<input type=\'password\' name=\'password\' id=\'password\' maxlength=\"60\" />
<input type=\'submit\' name=\'Submit\' value=\'Submit\' />
</fieldset>
</form>
form validation:
var frm = new Validator(\"registration\");
frm.EnableOnPageErrorDisplay();
frm.EnableMsgsTogether();
frm.addValidation(\"username\",\"req\",\"Please enter your username\");
frm.addValidation(\"email\",\"req\",\"Please enter your email address\");
frm.addValidation(\"email\",\"email\",\"Please enter a valid email address\");
frm.addValidation(\"useraddress\",\"req\",\"Please enter a useraddress\");
frm.addValidation(\"password\",\"req\",\"Please enter a password\");
code for the submission:
function UserRegistration()
{
if(!isset($_POST[\'submitted\']))
{
return false;
}
$formvars = array();
if(!$this->ValidateRegistrationSubmission())
{
return false;
}
$this->CollectRegistrationSubmission($formvars);
if(!$this->SaveToDatabase($formvars))
{
return false;
}
if(!$this->usrconfirmation($formvars))
{
return false;
}
$this->SendAdminIntimationEmail($formvars);
return true;
}
database validation:
function SaveToDatabase(&$formvars)
{
if(!$this->DBLogin())
{
$this->HandleError(\" login failed! or timeout\");
return false;
}
if(!$this->Ensuretable())
{
return false;
}
if(!$this->IsFieldUnique($formvars,\'email\'))
{
$this->HandleError(\"This email is already taken\");
return false; }
if(!$this->IsFieldUnique($formvars,\'username\'))
{
$this->HandleError(\"Already taken, try another\");
return false;
}
if(!$this->InsertIntoDB($formvars))
{
$this->HandleError(\"Insertion failure\");
return false; }
return true;}
Table creation:
function CreateTable()
{
$qry = \"Create Table $this->student (\".
\"id_user INT NOT NULL AUTO_INCREMENT ,\".
\"username VARCHAR( 128 ) NOT NULL ,\".
\"email VARCHAR( 64 ) NOT NULL ,\".
\"useraddress VARCHAR( 16 ) NOT NULL ,\".
\"password VARCHAR( 32 ) NOT NULL ,\".
\"PRIMARY KEY ( id_user )\".
\")\";
if(!mysql_query($qry,$this->connection))
{
$this->HandleDBError(\"bug in table creation \ query was\ $qry\");
return false;
} return true;
}
| <form id=\'registration\' action=\'registration.php\' method=\'post\' accept-charset=\'UTF-8\'> <fieldset > <legend>Registration</legend> <input type=\'name\' =\'submitted\' id=\'submitted\' value=\'1\'/> <label for=\'username\' >Username: </label> <input type=\'text\' name=\'username\' id=\'username\' maxlength=\"99\" /> <label for=\'email\' >Email Address:</label> <input type=\'text\' name=\'email\' id=\'email\' maxlength=\"13\" /> <label for=\'useraddress\' >Useraddress*:</label> <input type=\'text\' name=\'userad\' id=\'useraddress\' maxlength=\"70\" /> <label for=\'password\' >Password*:</label> <input type=\'password\' name=\'password\' id=\'password\' maxlength=\"60\" /> <input type=\'submit\' name=\'Submit\' value=\'Submit\' /> </fieldset> </form> form validation: 
 | 




