更新查询之前如何存储表的旧数据

时间:2019-02-26 01:23:49

标签: php mysql

如何在更新查询之前将所选ID的旧值存储在表中?我有此代码用于我的插入查询和更新查询。我想在UPDATE查询之前保存所选ID的旧值。

        <form method="post" id="reg-form" action="user_save">
              <div class="box-body">
                <div class="row">
                 <div class="col-md-12">
                  <table id="example1" class="table table-bordered table-striped" style="margin-right:-10px">
                    <thead>
                      <tr>
                  <th>RECRUITER</th>
  </tr>
                    </thead>
<?php
                    include('../dist/includes/dbcon.php');
                    $bdo=$_SESSION['name'];
                    $query=mysqli_query($con,"SELECT * FROM accounts_at ")or die(mysqli_error());

                    while($row=mysqli_fetch_array($query)){
                  $id=$row['id'];
                    $rec=$row['rec'];
<tr>
                   <td><?php echo $rec;?></td>
<td>
                              &nbsp;&nbsp;&nbsp;&nbsp;<a id="click" href="user_edit.php?id=<?php echo $id;?>">
                            <i class="glyphicon glyphicon-edit text-blue"></i></a>
                                 </td>

这是我的user_update查询。

    <?php session_start();
if(empty($_SESSION['id'])):
    header('Location:../index');
endif;
include('../dist/includes/dbcon.php');
$id = mysqli_real_escape_string($con, $_POST['id']);
$rec= mysqli_real_escape_string($con,$_POST['rec']);

mysqli_query($con,"UPDATE accounts_at set rec='$rec' where id='$id'")or 
die(mysqli_error());

echo "<script type='text/javascript'>alert('Successfully updated account 
details!');</script>";
echo "<script>document.location='update_acc'</script>";
?>

1 个答案:

答案 0 :(得分:0)

这取决于您要如何保存此数据? 您可以将其保存在文件中,因为可以使用fopen()并首先将其写入 或通过mail()将其发送给自己

$save_method = //method you want to save data
if($save_method){//code to update data}