Professional Documents
Culture Documents
WT 9
WT 9
MySql table. a) Design A HTML page which takes Name, Address, Email and Mobile
No. From user (register.php). b) Store this data in Mysql database / text file. c) Next page
display all user in html table using PHP (display.php).
CODE:
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h2>User Registration</h2>
<form action="register.php" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br><br>
<label for="address">Address:</label><br>
<input type="text" id="address" name="address" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="mobile">Mobile No.:</label><br>
<input type="text" id="mobile" name="mobile" required><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "users";
21
$sql = "INSERT INTO users (name, address, email, mobile) VALUES ('$name', '$address', '$email',
'$mobile')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>User List</title>
</head>
<body>
<h2>User List</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Mobile No.</th>
</tr>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "users";
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["address"]."</td>";
echo "<td>".$row["email"]."</td>";
echo "<td>".$row["mobile"]."</td>";
22
echo "</tr>";
}
} else {
echo "0 results";
}
$conn->close();
?>
</table>
</body>
</html>
OUTPUT:
23