I think the problem is with the mysqli_query. The code gives no error but if there was a problem with the database a "Failed to connect to MySQL" output will come out.
And if there was a problem with the insert code a Registration Failed out will come out it is doing neither of them. It simply flickers resets everything and then nothing.
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'registrations');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['register']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$division = $_POST['division'];
$programme = $_POST['programme'];
$department = $_POST['department'];
$phone_no = $_POST['phone_no'];
$msg=mysqli_query($con,"insert into register('firstname','lastname','age','email','gender','division','programme','department','phone_no') values ('$firstname','$lastname','$age','$email','$gender','$division','$programme','$department','$phone_no')");
if($msg)
{
echo '<script type="text/javascript">alert("Registered Successfully")</script>';
}
else
{
'<script type="text/javascript">alert("Registration Failed")</script>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<div class="container">
<div class="header">
<h2>Register</h2>
</div>
<form action="" method="POST" action="register.php">
<div class="input-group">
<label>First Name</label><br>
<input type="text" class="txt" name="firstname" required>
</div>
<div class="input-group">
<label>Last Name</label><br>
<input type="text" class="txt" name="lastname" required>
</div>
<div class="input-group">
<label>Age</label><br>
<input type="text" class="txt" name="age" required>
</div>
<div class="input-group"><br>
<label for="email">Email Address</label>
<input type="email" class="txt" name="email" required>
</div>
<div class="input-group">
<label>Gender</label><br>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
</div>
<div class="input-group">
<label>Division</label><br>
<select name="division">
<option value="">--select--</option>
<option value="Regular">Regular</option>
<option value="Extension">Extension</option>
</select>
</div>
<div class="input-group">
<label>Programme</label><br>
<select name="programme">
<option value="">--select--</option>
<option value="Degree">Degree</option>
<option value="Masters">Masters</option>
<option value="tvt">tvt</option>
</select>
</div>
<div class="input-group">
<label>Department</label><br>
<select name="department">
<option value="">--select--</option>
<option value="ComputerScience">Computer Science</option>
<option value="Accounting">Accounting</option>
<option value="Marketing">Marketing</option>
<option value="Tourism">Tourism</option>
</select>
</div>
<div class="input-group">
<label>Phone Number</label><br>
<input type="text" class="txt" name="phone_no" required>
</div>
<div class="input-group">
<button type="submit" class="btn" name="register">Register</button>
</div>
</form>
</div>
</body>
</html>
apparently it is because of the radio button i changed it to combo box and now works perfectly. i still don't understand why. and i also removed the action = ""