Forum Moderators: bakedjake

Message Too Old, No Replies

javascript alerts in php

         

mag1

12:39 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



I've got the following code in php but would prefer to have a javascript alert appear rather than printing the message.
<?php

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?

tomda

12:53 pm on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript is a client-side and PHP is a server-side.

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.

mag1

11:09 am on Nov 18, 2004 (gmt 0)

10+ Year Member



OK Thanks.