If you don’t want the page to reload, you’ll need javascript to validate the form before posting. Theres plenty of free javascript validation scripts on the net.
If you want a php based solution, you will need to write your page to first check POST for submit, if it finds it validate the data and if invalid, output the form with the post variables. If the data is valid, do whatever. And finally if there is no POST data display a blank form.
[php]<?php
include(‘connectdb.php’);
if(isset($_POST[‘submit’])) {
$stud_no=$_POST[‘stud_no’];
$password=$_POST[‘password’];
$lname=$_POST[‘lname’];
$fname=$_POST[‘fname’];
$gender=$_POST[‘gender’];
$religion=$_POST[‘religion’];
$civilstatus=$_POST[‘civilstatus’];
$nationality=$_POST[‘nationality’];
if($stud_no =='' || $password== ' ' || $lname== ' ' || $fname== ' ') {
echo "Please enter required data";}
?>
Personal Information |
*Student Number : |
Gender :
Male
Female
|
*Password : |
Religion : |
*Last Name : |
Civil Status :
>Single
Married
Widowed
Divorced
|
*First Name : |
Nationality : |
|
|
<?
else if(mysql_num_rows($query) > 0)
{
echo "Student Number is already in use.";
}
else {
$query = "insert into students (stud_no,password,lname,fname,gender,religion,civilstatus,nationality) values ('$stud_no','$password','$lname','$fname','$gender','$religion','$civilstatus','$nationality')";
mysql_query($query) or die (mysql_error());
echo "Student successfully added!";
header(“location:addstudents.php”);
}} else {
?>
Personal Information |
*Student Number : |
Gender :
Male
Female
|
*Password : |
Religion : |
*Last Name : |
Civil Status :
Single
Married
Widowed
Divorced
|
*First Name : |
Nationality : |
|
|
<? } ?>
[/php]
This is just a quick response, with possible errors in it, but you should be able to get the idea. I am after all eating my lunch as I type.