フォームを検証しました。「情報にエラーがあります。適切な情報を挿入してください」という検証メッセージをポップアップ表示したい。しかし、「情報にエラーがあります。適切な情報を挿入してください」という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>";
}
}
}
}
?>