我有一个从我的Android应用程序调用POST的php文件。目前,我有一个查询会将帖子值插入我的违规者表格。其中两个值是官员姓名和参考。现在,我想要做的还是运行另一个查询,该查询将更新 user_tbl 上的引用,其中officer_name = oname。 Officer_name是 user_tbl 中的列,oname是已发布的变量名称。我如何或以何种方式实现这一目标?
这是php代码。
<?php
$user_name = "dodolp";
$password = "dodolp";
$server = "localhost";
$db_name = "TMTRO";
$con = mysqli_connect($server,$user_name,$password,$db_name);
if ($con){
$Name = $_POST['name'];
$LName = $_POST['lname'];
$LNumber = $_POST['lnumber'];
$Violation = $_POST['violation'];
$Aplace = $_POST['aplace'];
$Address = $_POST['address'];
$PNumber = $_POST['pnumber'];
$OName = $_POST['oname'];
$RNumber = (int) $_POST['rnumber'];
$DTime = $_POST['dtime'];
$query = "insert into violators (name,lname,lnumber,violation,aplace,address,pnumber,oname,reference,datetime) values ('".$Name."','".$LName."','".$LNumber."','".$Violation."','".$Aplace."','".$Address."','".$PNumber."','".$OName."','".$RNumber."','".$DTime."');";
$sql = "UPDATE into user_tbl SET reference = '$RNumber' WHERE officer_name = '$OName'";
$result = mysqli_query ($con, $query);
if ($result)
{
$status = 'OK';
}
else
{
$status = 'FAILED';
}
}
else { $status = 'FAILED'; }
echo json_encode(array("response"=>$status));
mysqli_close($con);
?>
答案 0 :(得分:0)
你需要像这样运行两个查询:
$query = "insert into violators (name,lname,lnumber,violation,aplace,address,pnumber,oname,reference,datetime) values ('".$Name."','".$LName."','".$LNumber."','".$Violation."','".$Aplace."','".$Address."','".$PNumber."','".$OName."','".$RNumber."','".$DTime."');";
$result = mysqli_query ($con, $query);
$sql = "UPDATE user_tbl SET reference = '$RNumber' WHERE officer_name = '$OName'";
$result = mysqli_query ($con, $sql);