当我单击提交按钮时,它更新了一个表的相同ID,并删除了另一个表字段的相同ID。它将如何为我提供解决方案。
if($_POST['submit']=='update'){
$detail=mysql_real_escape_string($_POST['detail']);
$status='open';
$sid=$_POST['sid'];
$sql=mysql_query("UPDATE project_sheeting_production_dispatch SET status='$status' where sid=$sid") or die("Insertion Failed:" . mysql_error());
$sql1=mysql_query("DELETE project_sheeting_production_delivered where sid=$sid") or die("Insertion Failed:" . mysql_error());
答案 0 :(得分:0)
使用mysqli和参数作为一种好习惯
if($_POST['submit'] == 'update'){
$detail = mysql_real_escape_string($_POST['detail']);
$status = 'open';
$sid = trim($_POST['sid']);
$sql = $this->db_connect->prepare("UPDATE project_sheeting_production_dispatch SET status=? where sid=?");
if($sql === FALSE)
{
die('Error Update');
}
else
{
$sql->bind_param('ss',$status, $sid);
$sql->execute();
}
$sql2 = $this->db_connect->prepare("DELETE project_sheeting_production_delivered where sid=?");
if($sql2 === FALSE)
{
die('Error Delete');
}
else
{
$sql2->bind_param('s', $sid);
$sql2->execute();
}
$ this-> db_connect是您的数据库连接。