请我删除特定表中的记录,并将同一记录插入另一个表中。如果所有表包含相同的列但我需要在插入已删除记录的表中添加另一列,这样可以正常工作。
这是我的代码谢谢
<?php
// connect to the database
$con=mysqli_connect("localhost", "root", "");
if(mysqli_select_db($con, "e-office"));
$execute ='';
$Posting_User = mysqli_escape_string($con, $_SESSION[('Uname')]);
// confirm that the 'id' variable has been set
if (isset($_GET['execute'])) $execute = $_GET['execute'];
{
// get the 'id' variable from the URL
if($execute=='delete'){
$id = $_GET['id'];
// delete record from database
$sql = mysqli_query($con, "INSERT INTO tbl_income_approved SELECT * FROM
tbl_income WHERE (trn_no = '$id' AND Approved_by ='$Posting_User') ");
$sql = mysqli_query($con, "DELETE FROM tbl_income WHERE trn_no = '$id'");
if($sql)
// redirect user after delete is successful
header("Location: income_report.php");
else
// if the 'id' variable isn't set, redirect the user
echo "query not successful";
}
}
?>
答案 0 :(得分:0)
上帝是荣耀!我现在有一个工作代码,谢谢所有
<?php
session_start();
if(!$_SESSION[('Uname')]){
header("location:login.php");
}
// connect to the database
$con=mysqli_connect("localhost", "root", "");
if(mysqli_select_db($con, "e-office"));
$execute ='';
$Posting_User = mysqli_escape_string($con, $_SESSION[('Uname')]);
// confirm that the 'id' variable has been set
if (isset($_GET['execute'])) $execute = $_GET['execute'];
{
$id = $_GET['id'];
///testing
$sql="SELECT * FROM tbl_income WHERE trn_no='$id'";
$result=mysqli_query($con, $sql);
//echo $count;
while($row = mysqli_fetch_assoc($result)){
$Posting_User = mysqli_escape_string($con, $row['Posting_User']);
$date = mysqli_escape_string($con, $row['date']);
$rno = mysqli_escape_string($con, $row['rno']);
$source = mysqli_escape_string($con, $row['source']);
$subsidiary = mysqli_escape_string($con, $row['subsidiary']);
$deposit = mysqli_escape_string($con, $row['deposit']);
$amount = mysqli_escape_string($con, $row['amount']);
$narration = mysqli_escape_string($con, $row['narration']);
$timestamp = mysqli_escape_string($con, $row['timestamp']);
$trn_no = mysqli_escape_string($con, $row['trn_no']);
$Approved_by = mysqli_escape_string($con, $_SESSION[('Uname')]);
$sql=mysqli_query($con, "INSERT INTO tbl_income_approved (Posting_User, date, rno, subsidiary, deposit, source, amount, narration, Approved_by) VALUES ('$Posting_User','$date','$rno', '$subsidiary', '$deposit', '$source', '$amount', '$narration', '$Approved_by')");
}
///close testing
// get the 'id' variable from the URL
if($execute=='delete'){
$id = $_GET['id'];
$sql = mysqli_query($con, "DELETE FROM tbl_income WHERE trn_no = '$id'");
if($sql)
// redirect user after delete is successful
header("Location: income_report.php");
else
// if the 'id' variable isn't set, redirect the user
echo "query not successful";
}
}
?>