Home  >  Q&A  >  body text

The following code cannot modify the information. It seems that the ID cannot be obtained or the information cannot be modified due to incorrect acquisition.

edit.php file code is as follows:

<?php
include("./config/conn.php");//The content is related to connecting to the database
$id = $ _GET['id'];
$pid = $_POST['pid'];
$name = $_POST['name'];
$dept = $_POST['dept'];
$phone = $_POST['phone'];
$tel = $_POST['tel'];
$time = date("Y-m-d H:i:s");
if( $conn){
$sql = "update txl set pid='$pid',name='$name',dept='$dept',phone='$phone',tel='$tel',cre_time ='$time' where id='$id'";
$que = mysqli_query($conn,$sql);
if($que){
echo "<script>alert(' The modification is successful and returns ');location.href='txl_list.php';</script>";
}else{
                                                                                                                     ='txl_list.php';</script>";
}
}
?>

---------------- ------------------------------------------

The above code Medium:

$sql = "update txl set pid='$pid',name='$name',dept='$dept',phone='$phone',tel='$tel', cre_time='$time' where id='$id'";

The specific id value can be modified by directly specifying id='$id'". I don’t know why, but it feels like the id value is obtained. question

------------------------------------------- --------------------------

Modify the page code as follows:

<html>

<head>
   <title></title>
   <link rel="stylesheet" type="text/css" href="./CSS/style.css">
</head>
<body>
<?php include("header.php");?>
<?php
include("./config/conn.php");
$id = $_GET['id'];
$sql = "select * from txl where id='$id'";
$que = mysqli_query($conn,$sql);
$rw = mysqli_fetch_assoc($que);
?>
<div class="div1">
   <form action="edit.php" method="post">
       <input type="hidden" name="id" value="<?php echo $rw['pid'];?>">
       <p>用户编号:<input type="text" name="pid" value="<?php echo $rw['pid'];?>"></p>
       <p>用户姓名:<input type="text" name="name" value="<?php echo  $rw['name'];?>"></p>
       <p>用户部门:<select id="dept" name="dept">
               <option value="<?php echo  $rw['dept'];?>"><?php echo  $rw['dept'];?></option>
                <option name="cwk">财务科</option>
               <option name="sjk">审计科</option>
                <option name="bwk">保卫科</option>                
           </select></p>
       <p>手机号码:<input type="text" name="phone"value="<?php echo  $rw['phone'];?>"></p>
       <p>办公电话:<input type="text" name="tel"value="<?php echo  $rw['tel'];?>"></p>
       <p><input type="submit" value="修改">  <input type="reset" value="重置"></p>
   </form>
</div>
<?php include ("footer.html");?>
</body>
</html>


##Click on the modification prompt and it will be successful. In fact, the data has not been modified. Could you please tell me where the problem is?

不吃玉米糖不吃玉米糖2548 days ago1291

reply all(2)I'll reply

  • 不吃玉米糖

    不吃玉米糖2017-10-25 19:27:41

    I found the problem. I used POST submission on the submission page <form action="edit.php" method="post">

    The receiving page should also be in POST mode, put $id = $_GET['id']; Change to $id = $_POST['id']; That's it

    reply
    0
  • Eli

    Eli2017-10-07 11:13:34

    You first output $_GET['id'] in the php file to see if you can get the value, or whether your parameter names are written correctly

    reply
    0
  • 不吃玉米糖

    The ID number can be obtained correctly,

    不吃玉米糖 · 2017-10-07 20:39:22
    不吃玉米糖

    http://localhost/test/TongXunLu/txl_edit.php?id=1 Click the modify button to obtain the ID value normally

    不吃玉米糖 · 2017-10-07 20:41:26
    Eli

    Try exchanging the single and double quotes in the SQL statement, like this: $sql = 'update txl set pid="$pid",name="$name",dept="$dept",phone="$phone",tel="$tel",cre_time="$time" where id ="$id"';

    Eli · 2017-10-08 08:58:12
  • Cancelreply