我已经验证了我的表格。我想弹出一条验证消息“信息有错误,请插入正确的信息”。但出现2个弹出框“信息有错误,请插入正确的信息”。和“谢谢!您的订单已下达!”。我可以知道是什么问题吗?
$fnameErr=$lnameErr=$add1Err=$add2Err=$postErr=$mobileErr=$creditErr=$pinErr ="";
$credit=$pin="";
if($_REQUEST['command']=='update')
{
$date = date('Y-m-d');
$time = date("H:i:s");
$charge = $_REQUEST['ocharge'];
$fname = $_REQUEST['ofname'];
$lname = $_REQUEST['olname'];
$mobile = $_REQUEST['omobile'];
$add1 = $_REQUEST['oadd1'];
$add2 = $_REQUEST['oadd2'];
$postcode = $_REQUEST['opostcode'];
$state = $_REQUEST['ostate'];
$country = $_REQUEST['ocountry'];
$credit = $_REQUEST['ocredit'];
$pin = $_REQUEST['opin'];
$city = $_REQUEST['ocity'];
if($fname==""||$lname==""||$mobile==""||$add1 ==""||$add2 ==""||$postcode==""||$state ==""||$country==""||$credit==""||$pin==""||$city=="")
{
?>
<script type="text/javascript">
alert("Please fill in all the required informations.");
</script>
<?php
}
else
{
$sql=" INSERT INTO `order` (Order_Date,Order_Time,Delivery_Charge,
Delivery_Fname,Delivery_Lname,Delivery_HP,Delivery_Street1,
Delivery_Street2,Delivery_Postcode,Delivery_State,
Delivery_Country,Credit_No,Pin_No,Delivery_City,Order_Status)
VALUES
('$date','$time','$charge','$fname','$lname','$mobile',
'$add1','$add2','$postcode','$state','$country',
'$credit','$pin','$city','Pending')";
$result=mysql_query($sql);
if($result === FALSE)
{
die("Query Failed!".mysql_error().$result);
}
$orderid=mysql_insert_id();
if (empty($errors) === true)
{
//fname xx
if (!preg_match("/^[A-Z][a-zA-Z -]+$/i", $_REQUEST['ofname']))
{
$fnameErr= 'Your first name cannot contain with any symbol and number';
}
//lname xx
if (!preg_match("/^[A-Z][a-zA-Z -]+$/i",$_REQUEST['olname']) )
{
$lnameErr= 'Your last name cannot contain with any symbol and number';
}
//add1 xx
if (!preg_match("/^[a-zA-Z0-9 _.,:\"\']+$/i",$_REQUEST['oadd1']))
{
$add1Err = 'Address 1 must be only letters, numbers or one of the following';
}
//add2 xx
if (!preg_match("/^[a-zA-Z0-9 _.,:\"\']+$/i",$_REQUEST['oadd2']))
{
$add2Err= 'Address 2 must be only letters, numbers or one of the following';
}
//postcode xx
if (!preg_match("/^\d{5}$/i", $_REQUEST['opostcode']))
{
$postErr = 'Postcode must be 5 digits';
}
//mobile xx
if (!preg_match("/^\d{3}-\d{7}$/i", $_REQUEST['omobile']))
{
$mobileErr= 'Phone must comply with this mask: 010-1111111 or 0111-1111111';
}
//credit card xx
if (!preg_match("/^\d{4}-\d{4}-\d{4}-\d{4}$/i", $_REQUEST['ocredit']))
{
$creditErr= 'Credit Card must comply with this mask: 0000-1111-2222-3333';
}
//pin xx
if (!preg_match("/^\d{6}$/i", $_REQUEST['opin']))
{
$pinErr = 'Pin must be 6 digits';
}
?>
<script type="text/javascript">
alert("Information has some error,please insert the proper information.");
</script>
<?php
}
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++)
{
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$insert_query="INSERT INTO order_detail (Order_ID,Product_ID,Order_Quantity,Sub_Total) VALUES ('$orderid','$pid','$q','$price')";
if(mysql_query($insert_query))
{
echo"<script>alert('Thank You! your order has been placed!')</script>";
}
}
}
}
?>