SPG-0473
Web Programming
(Practical Test)
Name: Mohamad Luqman Hakim Bin Mohd Zainudin
(NWS 19010059)
Class: Network Security Sem 4
TTO’s Name: Ms. Hairun Nisa Daud
Web Programming - CIT 0473
INDUSTRIAL ELECTRONICS DEPARTMENT
Table of Contents
1. register.html.................................................................................................................................................. 4
2. registerprocess.php...................................................................................................................................... 5
3. database....................................................................................................................................................... 6
4. userregistration.txt........................................................................................................................................ 7
Page 2 of 7
Web Programming - CIT 0473
INDUSTRIAL ELECTRONICS DEPARTMENT
PRACTICAL TEST (WEB PROGRAMMING)
Create a HTML page like Figure 1 called register.html that requires user to fill in the form and PHP page
like Figure 2 called registerprocess.php to received and display the information to the user.
All information from user in register.html file will be saved in a database. All information about the
database and table refer to Table 1. Schema for table userregistration refer to Figure 3. Write this
process in registerprocess.php.
Write a PHP script in registerprocess.php to save all information in text file called userregistration.txt.
Welcome NorulMubarakah!
Please fill in the form correctly! Your name is NorulMubarakah Ibrahim
Insert your First Name : You are 29 years old and staying at Kelantan.
NorulMubarakah
Insert your Last Name : Ibrahim
Insert your age :
Figure 2: registerprocess.php
Insert your State : : 29
Kelantan
Submit userregistration(FirstName, LastName, Age, State)
Figure 1: register.html Figure 3 : table schema
Database Name Table 1 : Database information
Table Name db_register
Location user_registration
UserName localhost
Password root
-
Page 3 of 7
Web Programming - CIT 0473
INDUSTRIAL ELECTRONICS DEPARTMENT
1. register.html
a) Source Code
<html>
<body>
<form action="registerprocess.php" method="post">
<table>
<TR>
<TD>Insert your First Name:</TD>
<TD><INPUT TYPE="text" NAME="fname" SIZE="40" MAXLENGTH="80"></TD>
</TR>
<TR>
<TD>Insert your Last Name:</TD>
<TD><INPUT TYPE="text" NAME="lname" SIZE="40" MAXLENGTH="80"></TD>
</TR>
<TR>
<TD>Insert your Ages:</TD>
<TD><INPUT TYPE="text" NAME="age" SIZE="40" MAXLENGTH="80"></TD>
</TR>
<TR>
<TD>Insert your State:</TD>
<TD><INPUT TYPE="text" NAME="state" SIZE="40" MAXLENGTH="80"></TD>
</TR>
<TR>
<TD><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit"></TD>
</TR>
</table>
</form>
</body>
</html>
b) Output
Page 4 of 7
Web Programming - CIT 0473
INDUSTRIAL ELECTRONICS DEPARTMENT
2. registerprocess.php
a) Source Code
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>! <br />
Your name is <?php echo $_POST["fname"]; ?> <?php echo $_POST["lname"]; ?> <br />
You are <?php echo $_POST["age"]; ?> years old and staying at <?php echo $_POST["state"]; ?>
</html>
</body>
b) Output
Page 5 of 7
Web Programming - CIT 0473
INDUSTRIAL ELECTRONICS DEPARTMENT
3. Database
a) Source Code
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "db_register";
$First = $_POST['fname'];
$Last = $_POST['lname'];
$Ages = $_POST['age'];
$State = $_POST['state'];
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$query = "INSERT INTO `user registration`(`firstname`, `lastname`, `age`, `state`) VALUES
('$First','$Last','$Ages','$State')";
$result = mysqli_query($connect,$query);
if($result)
{
echo 'Data Inserted';
}else{
echo 'Data not Inserted';
}
?>
b) Output
Page 6 of 7
Web Programming - CIT 0473
INDUSTRIAL ELECTRONICS DEPARTMENT
4. userregistration.txt
a) Source Code
<?php
extract($_REQUEST);
$file=fopen("userregistration.txt","a+");
fwrite($file,"firstname :");
fwrite($file, $First ."\n");
fwrite($file,"lastname :");
fwrite($file, $Last ."\n");
fwrite($file,"Ages :");
fwrite($file, $Ages ."\n");
fwrite($file, "State :");
fwrite($file, $State ."\n");
fclose($file);
header("location: register.html");
?>
b) Output
Page 7 of 7