使用php更新数据库中特定id的详细信息

5kgi1eie  于 2021-06-21  发布在  Mysql
关注(0)|答案(4)|浏览(379)

我想更新editentries.php中输入的详细信息。但当我输入详细信息并单击更新时,它并没有在数据库中更新。我正在使用replace查询来完成它。帮帮我,我该怎么办?
这是editentries.php

if(isset($_POST['edit']) && isset($_POST['editid'])){
  $id = $_POST['editid'];
  $selectname=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY name");
  $selectaddress=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY address");
  $selectemail=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY email");
  $selectphoneno=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY phoneno");
  $selectprice=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY price");

?>
<div class="col-lg-10 col-md-10 col-sm-10"><br><br><br>
  <h2>Update Applicant Details</h2><hr>
  <div class="col-lg-8 col-md-8 col-sm-8">
<form method="post" action="entries.php">
  <div class="form-group row">
    <label for="inputEmail3" class="col-sm-2 col-form-label">Applicant ID:</label>
    <div class="col-sm-10">

      <?php  
        echo '<input type="text" class="form-control" id="inputEmail3" name="id" readonly value="'.$id.'">';

       ?>

    </div>
  </div>
  <div class="form-group row">
    <label for="inputEmail3" class="col-sm-2 col-form-label">Name:</label>
    <div class="col-sm-10">
      <?php  while($res=mysqli_fetch_array($selectname)){
        echo '<input type="text" class="form-control" id="inputEmail3" name="name" value="'.$res['name'].'">';
      }
       ?>
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Address:</label>
    <div class="col-sm-10">
     <?php  while($res=mysqli_fetch_array($selectaddress)){
        echo '<textarea class="form-control" id="inputEmail3" name="address">'.$res['address'].'</textarea>';
      }
       ?>
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Phone no.:</label>
    <div class="col-sm-10">
     <?php  while($res=mysqli_fetch_array($selectphoneno)){
        echo '<input type="text" class="form-control" id="inputEmail3" name="phoneno" value="'.$res['phoneno'].'">';
      }
       ?>
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Email ID:</label>
    <div class="col-sm-10">
     <?php  while($res=mysqli_fetch_array($selectemail)){
        echo '<input type="text" class="form-control" id="inputEmail3" name="email" value="'.$res['email'].'">';
      }
       ?>
    </div>
  </div>
  <div class="form-group row">
    <div class="col-sm-10">
      <input type="submit" class="btn btn-primary" name="update" value="Update">
    </div>
  </div>

<?php 
if(isset($_POST["id"]) && isset($_POST["name"]) && isset($_POST["address"]) && isset($_POST["phoneno"]) && isset($_POST["email"]) && isset($_POST['update']))
{
  $sid= $_POST["id"]; 
$name= $_POST["name"];
$address=$_POST["address"];
$phoneno= $_POST["phoneno"];
$email= $_POST["email"];

$update="REPLACE INTO feedetails(id,subjects,price,name,address,email,phoneno) VALUES ('$sid','$name','$address','$email','$phoneno')";

if(mysqli_query($conn,$update))
{
echo " <SCRIPT LANGUAGE='Javascript'>
    window.alert('Record updated');
    window.location.href='entries.php';
    </SCRIPT>";
}
else
{
  mysqli_error($conn);
}
}
} ?>

我想在数据库中更新该特定id的详细信息,但它根本不起作用

nuypyhwy

nuypyhwy1#

“更新您的表集name='$name',address='$address',email='$email',phoneno='$phoneno',其中id='$sid'”

oalqel3c

oalqel3c2#

$query=" UPDATE /*table-name */ SET  name='$_POST[name]' WHERE id= ' ".$id." ' " ;

example:-

$query=" UPDATE register SET  name='$_POST[name]' WHERE id= ' ".$id." ' " ;
tvz2xvvm

tvz2xvvm3#

使用ajax&jquery将id添加到提交按钮,即id=“delsub”,而不是提交delete以返回javascript

$("#delsub").click(function(){
var id = $("#id").val();
dataString = "delete=" + id;
$.ajax({
type: "POST",
url: "deleteentry.php",
data: dataString,
cache: false,
success: function(html)
{
    alert('Record deleted');
    window.location.href='entries.php';
}
});
});

在deleteentry.php中,将$\u请求更改为$\u post

balp4ylt

balp4ylt4#

sql中的replace函数用于更新字符串的内容,而不是用于更新数据。
可以使用sql update语句。
所以你的sql查询是这样的,
$update=“update feedetails set name=”..$name.”,address=”..$address.”,email=“”..$email.”,phoneno=“”..$phoneno.”,其中id=“”..$id;

相关问题