5.create a registration form and display the details in the other PHP page.
Create a mock registration form for an online retail web site. the form should output the appropriately formatted contents of a valid form and thank the user for submitting. An invalid form should be returned to the user indicating the problems with the submitted data.
Username-max15 char, letters and number only
Password – minimum length 4 char
Email – valid email structure
Date of birth – a customer should be at least 18 years of age
Name- maximum 50 char
Acceptance of terns & conditions
Their choice regarding email promotions to be received if an email address was given
Create a folder "registration" inside localdisk c/xampp/htdocs
create a file database.php and paste a code
database.php
<?php
$conn= new mysqli('localhost','root','','registration')or die("Could not connect to mysql".mysqli_error($con));
?>
create another file index.php and paste a code
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration</title>
</head>
<body>
<style>
body{
margin: 0px;
padding: 0px;
}
.container{
height: 650px;
text-align: center;
}
.box{
border: 2px black solid;
height: 500px;
width: 500px;
margin: 30px auto;
text-align: center;
padding: 20px;
border-radius: 30px;
}
.formdata input{
width: 90%;
padding: 10px;
margin: 5px;
border-radius: 10px;
border: 1px black solid;
}
.formdata select{
width: 90%;
padding: 10px;
margin: 5px;
border-radius: 10px;
border: 1px black solid;
}
.formbutton input{
padding: 10px;
background-color:forestgreen;
border: none;
border-radius: 10px;
color: white;
margin: 20px;
width: 30%;
}
.formbutton input:hover{
background-color: rgb(5, 95, 5);
cursor: pointer;
}
</style>
<div class="container">
<h1>USER REGISTRATION USING PHP AND MYSQL</h1>
<div class="box">
<h2>REGISTER HERE</h2>
<form action="index.php" method="POST" enctype="multipart/form-data">
<div class="formdata">
<input type="text" name='name' placeholder="ENTER YOUR NAME" maxlength='50' required>
</div>
<div class="formdata">
<input type="email" name='email' placeholder="ENTER YOUR EMAIL" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2, 4}$" required>
</div>
<div class="formdata">
<input type="date" name='dob' placeholder="ENTER YOUR DATE OF BIRTH" required>
</div>
<div class="formdata">
<input type="text" name='username' placeholder="ENTER YOUR USERNAME" pattern="[A-Za-z0-9]+" required>
</div>
<div class="formdata">
<input type="password" name='password' placeholder="ENTER YOUR PASSWORD" minlength='4' required>
</div><br>
<div class="#">
<input type="checkbox" name='tandc' value='Agreed' required>Make sure that you agree our Terms & Conditions to continue.
</div><br>
<div class="formdata">
<select name="receiveemail" id="" required>
<option value="">RECEIVE EMAIL?</option>
<option value="yes">YES</option>
<option value="no">NO</option>
</select>
</div>
<div class="formbutton">
<input type="submit" name="submit" value="REGISTER">
<a href="display.php"><input type="button" name="submit" value="VIEW RECORDS"></a>
</div>
</form>
</div>
</div>
</body>
</html>
<?php
include_once 'database.php';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$username = $_POST['username'];
$password = $_POST['password'];
$tandc = $_POST['tandc'];
$receiveemail = $_POST['receiveemail'];
$sql = "INSERT INTO users (fullname,uemail,udob,uusername, upassword, tandc, receiveemail)
VALUES ('$name','$email','$dob','$username', '$password', '$tandc', '$receiveemail')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully !";
} else {
echo "Error: " . $sql . "
" . mysqli_error($conn);
}
mysqli_close($conn);
}
?>
Create another file display.php and paste a code
display.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="index.php">HOME</a>
</body>
</html>
<?php
include_once 'database.php';
$str="SELECT * from users";
if($result = mysqli_query($conn, $str)){
if(mysqli_num_rows($result) > 0){
echo "<table style='width:80%;margin:auto'>";
echo "<tr style='background-color:blue;color:white;font-size:24px'>";
echo "<th>ID</th>";
echo "<th>NAME</th>";
echo "<th>EMAIL</th>";
echo "<th>DOB</th>";
echo "<th>USERNAME</th>";
echo "<th>T&C</th>";
echo "<th>Receive Email</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr style='background-color:yellow;color:black'>";
echo "<td>" . $row['uid'] . "</td>";
echo "<td>" . $row['fullname'] . "</td>";
echo "<td>" . $row['uemail'] . "</td>";
echo "<td>" . $row['udob'] . "</td>";
echo "<td>" . $row['uusername'] . "</td>";
echo "<td>" . $row['tandc'] . "</td>";
echo "<td>" . $row['receiveemail'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
?>
Start xampp control panel
And create a database "registration" in localhost/phpmyadmin
and inside registration database create table "users" and add the attributes shown in below screenshot
RUN THE URL-
localhost/registration
Comments
Leave a comment