Forum Moderators: bakedjake
if ($submit)
{
if(!$CustName)
{//I'd like a javascript alert here if CustName is left empty
$error = "Customer Name not Entered!";
}
if (!$submit ¦¦ $error)
{
echo $error;
}
else{
$db = mysql_connect("Database", "UserName", "Password");
mysql_select_db("DBName", $db);
$sql =mysql_query("INSERT INTO tblComplaint(Name, Address1, Address2, Address3, Address4, Phone, Email, Complaint, SortCode, Branch, Date)VALUES ('$CustName', '$Address1', '$Address2', '$Address3', '$Address4', '$Phone', '$Email', '$Complaint', '$SortCode', '$Branch', now())",$db);
if ($sql)
{
echo "Complaint Entered";
}
else
{
echo "ERROR: " . mysql_error();
}
}
}
?>
Is there any suggestions as to how this can be done?
Sure, it may be possible to have an alert message in javascript when the field is empty using PHP but what is the use?
The advantage of javascript is that, being a client-side script, the user do not have to reload the page to find out it has forgotten a field.
The disadvantage is that some users are javascript disable and they will not get the alert msg.
Seeing your script, I would stick with PHP.