Here is your corrected and functional HTML + PHP + JavaScript Student Registration Form code.
I have
removed all errors, corrected logic, syntax, and form handling:
---
✅ Fixes Made:
Corrected missing comma in database connection.
Fixed SELEECT typo to SELECT.
Fixed mismatched variable names.
Corrected form tag’s action and method syntax.
Moved PHP $_POST variable correctly.
Ensured mysqli_connect works properly.
Added table columns to INSERT INTO.
Fixed missing semicolon and echo in PHP.
Matched field id with input name.
<!DOCTYPE html>
<html>
<head>
<title>Student Registration</title>
<style>
table {
border-collapse: collapse;
table, th, td {
border: 2px solid black;
padding: 8px;
</style>
</head>
<body>
<script>
function validateForm() {
var id = [Link]('r').[Link]();
var user = [Link]('u').[Link]();
var address = [Link]('a').[Link]();
var email = [Link]('e').[Link]();
if (id === "") {
alert("Registration ID is required.");
return false;
if (user === "") {
alert("Username is required.");
return false;
if (address === "") {
alert("Address is required.");
return false;
if (email === "") {
alert("Email address is required.");
return false;
return true;
</script>
<?php
// Database connection
$con = mysqli_connect("localhost", "root", "", "madu");
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST["reg"];
$username = $_POST["user"];
$address = $_POST["address"];
$email = $_POST["email"];
// Check for duplicate ID
$s = "SELECT id FROM com225 WHERE id='$id'";
$avoid_duplicate = mysqli_query($con, $s);
$count = mysqli_num_rows($avoid_duplicate);
if ($count > 0) {
echo "<script>alert('Sorry, this record already exists.');</script>";
} else {
$sql = "INSERT INTO com225 (id, username, address, email) VALUES ('$id', '$username', '$address',
'$email')";
if (mysqli_query($con, $sql)) {
echo "<script>alert('Registration Successful');</script>";
} else {
echo "Error: " . mysqli_error($con);
?>
<form method="POST" onsubmit="return validateForm()">
<table>
<tr>
<th colspan="2">Life Shopping - Student Registration</th>
</tr>
<tr>
<td>ID:</td>
<td><input type="text" name="reg" id="r"></td>
</tr>
<tr>
<td>USERNAME:</td>
<td><input type="text" name="user" id="u"></td>
</tr>
<tr>
<td>ADDRESS:</td>
<td><input type="text" name="address" id="a"></td>
</tr>
<tr>
<td>EMAIL:</td>
<td><input type="text" name="email" id="e"></td>
</tr>
<tr>
<th colspan="2"><button type="submit">Submit</button></th>
</tr>
</table>
</form>
</body>
</html>