Hello there, I have a form and when data is inputted it goes into the table and I can get it out pefectly fine, the problem I have is that if the promary key is empty it will not submit, but if any of the other fields are empty except the primary key then the forms submits.
Is there a way to stop the form submitting unless all the fields are filled in first?
[PHP]<?php
// this starts the session
session_start() ;
?>
<?php
$db_name="proje ct"; // Database name
$tbl_name="memb er"; // Table name
// Connect to server and select database.
mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
mysql_select_db ("$db_name") or die("cannot select DB");
// Get values from form
$memberno=$_POS T['Member_No'];
$surname=$_POST['Surname'];
$forename=$_POS T['Forename'];
$address=$_POST['Address'];
$dob=$_POST['DOB'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(Membe r_No, Surname, Forename, Address, DOB)VALUES('$me mberno', '$surname', '$forename', '$address', '$dob')";
$result=mysql_q uery($sql);
// if successfully insert data into database, displays message "Successful ".
if($result){
header('Locatio n: blank.php');
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>[/PHP]
Any help or ideas would be very welcome.
Thank you in advanced.
Is there a way to stop the form submitting unless all the fields are filled in first?
[PHP]<?php
// this starts the session
session_start() ;
?>
<?php
$db_name="proje ct"; // Database name
$tbl_name="memb er"; // Table name
// Connect to server and select database.
mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
mysql_select_db ("$db_name") or die("cannot select DB");
// Get values from form
$memberno=$_POS T['Member_No'];
$surname=$_POST['Surname'];
$forename=$_POS T['Forename'];
$address=$_POST['Address'];
$dob=$_POST['DOB'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(Membe r_No, Surname, Forename, Address, DOB)VALUES('$me mberno', '$surname', '$forename', '$address', '$dob')";
$result=mysql_q uery($sql);
// if successfully insert data into database, displays message "Successful ".
if($result){
header('Locatio n: blank.php');
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>[/PHP]
Any help or ideas would be very welcome.
Thank you in advanced.
Comment