我正在发送来自Android应用程序的请求(字符串请求)当数据插入到数据库中,它工作正常,但有时它插入一个重复的值与新的订单号我搜索很多和广告检查,但它不工作当wifi或网络信号下降时,有时会发生这种情况有谁能指导我如何在php中处理它
这是我的Php Api<?php
// PHP code goes here
include'config.php';
$today = date("m");
//$year=date("y");
$day=date("d");
$rand = strtoupper(substr(uniqid(sha1(time())),0,5));
$unique = $today.$rand.$day;
$reason_=$_POST["reason"];
$s_number = $_POST["s_number"];
$datetime_pri=$_POST["datetime_pri"];
$bill=$_POST["bill"];
$customer_address=$_POST["customer_address"];
$customer_name=$_POST["customer_name"];
$customer_phone=$_POST["customer_phone"];
$date_time_order=$_POST["date_time_order"];
$dilvery_charges=$_POST["dilvery_charges"];
$phone_number=$_POST["phone_number"];
$price=$_POST["price"];
$shopname= $shopname= addslashes($_POST["shopname"]);
$status=$_POST["status"];
$total_bill=$_POST["total_bill"];
$emailcus=$_POST["emailcus"];
$id_customer=$_POST["id_cus"];
if(isset($_POST["phone_number"]))
{
$sql_u = "SELECT * FROM Customer_order WHERE customer_phone = '$customer_phone' AND date_time_order = '$date_time_order' AND phone_number = '$phone'";
$res_u = mysqli_query($con, $sql_u);
if (mysqli_num_rows($res_u) > 0) {
echo "Data already taken";
}
else
{
$sqlll="INSERT INTO `Customer_order`(`s_number`, `datetime_pri`,
`bill`, `customer_address`, `customer_name`,
`customer_phone`, `date_time_order`, `dilvery_charges`,
`phone_number`, `price`, `shopname`, `status`, `total_bill`, `reason`,`ordernumber`,`customer_email`,`customerId`)
VALUES ('$s_number','$datetime_pri','$bill','$customer_address','$customer_name',
'$customer_phone','$date_time_order','$dilvery_charges','$phone_number', '$price','$shopname','$status','$total_bill',
'$reason_','$unique','$emailcus','$id_customer')";
if ($con->query($sqlll) === TRUE) {
echo "successfully" . "<br>";
} else {
echo "Error: " . $sqlll . "<br>" . $con->error;
}
}
$content = $_POST['list_items'];
//echo $content;
$json = json_decode($content, true);
foreach ($json as $key => $value) {
// echo $value['Customer_phone'];
// perform other actions.
$itemprice=$value['price'];
$quantity= $value['Item_quantity'];
$price=$value['Items_price'];
$totall= $value['Total_bill'];
$dilivery= $value['dilvery_charges'];
//$shopname= $value['shopname'];
$shopname= addslashes($value['shopname']);
$shopnumber=$value['phone_number'];
$customerphone=$value['Customer_phone'];
$latitude= $value['lattitude'];
$lontitude= $value['longtitude'];
$bill=$value['Total_bill'];
$date= $value['date_time_order'];
$itemname= addslashes( $value['Item_name']);
$sub_detail=addslashes($value['description']);
$sql_uu = "SELECT * FROM customer_Orders_Items WHERE customer_phone= $customerphone AND date_time_order= $date AND item_name = $itemname";
$res_uu = mysqli_query($con, $sql_uu);
if (mysqli_num_rows($res_uu) > 0) {
echo "Data already taken";
}
else
{
$sql="INSERT INTO `customer_Orders_Items`(`customer_phone`,
`date_time_order`,
`dilvery_charges`,
`item_name`,
`item_quantity`,
`items_price`,
`lattitude`,
`longtitude`,
`phone_number`,
`price`,
`shopname`,
`total_bill`,
`sub_detail`,
`orderNo`) VALUES (
'$customerphone',
'$date',
'$dilivery',
'$itemname',
'$quantity',
'$price',
'$latitude',
'$lontitude',
'$shopnumber',
'$itemprice',
'$shopname',
'$totall',
'$sub_detail'
,'$unique')";
if ($con->query($sql) === TRUE) {
//echo "items add successfully";
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
}
;
}
}
// $con->close();
?>
顺序号在插入重复数据时改变,因为它是在API端创建的
在android代码中,你必须使用布尔变量来检查双击/多次点击
boolean send = false;
if(!send){
send = true;
//start volley
}