不保存在数据库表中

时间:2017-05-12 06:08:46

标签: php mysql mysqli

我想在db表中编辑记录,但它不保存在db表中,并且在提交此表单后没有任何更改。

这里是我忘了放的代码。

atomic<bool>

这是我的php代码

<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages
$id_doc=$_REQUEST['id_doc'];
$query = "SELECT * from doc where id_doc='".$id_doc."'"; 
$result = mysqli_query($connection, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
?>

2 个答案:

答案 0 :(得分:0)

不是答案。评论太长了。

除了参数化查询的问题,我发现这更容易阅读:

UPDATE doc 
   SET title = '$title'
     , date = '$date'
     , from_to = '$from_to'
     , details = '$details'
     , d_location = '$d_location'
     , d_stat = '$d_stat' 
 WHERE id_doc = '$id_doc'

现在看看参数化查询

答案 1 :(得分:-1)

尝试以下:

<?php
   if(isset($_POST['new']) && $_POST['new']==1)
    {

        $id_doc=$_REQUEST['id_doc'];
        $query = "SELECT * from doc where id_doc='".$id_doc."'"; 
        $result = mysqli_query($connection, $query) or die ( mysqli_error());
        $row = mysqli_fetch_assoc($result);

        $title =$_REQUEST['title'];
        $date = $_REQUEST['date'];
        $from_to = $_REQUEST['from_to'];
        $details = $_REQUEST['details'];
        $d_location = $_REQUEST['d_location'];
        $d_stat = $_REQUEST['d_stat'];

        $update="update doc set title='".$title."', date='".$date."', from_to='".$from_to."', details='".$details."', d_location='".$d_location."', d_stat='".$d_stat."' where id_doc='".$id_doc."'";
        if(mysqli_query($connection, $update)) {
          $status = "File Record Updated Successfully. </br></br><a href='v_doc.php'>View Updated Record</a>";            
         } else {
           die(mysqli_error($connection));
         }
        echo '<p style="color:#FF0000;">'.$status.'</p>';
    } else {
        // here some else code
    }
?>

一旦你得到它,这应该会向你显示确切的错误。在这里显示,所以我们可以检查并做更正。