[英]When Clicked edit button, corresponding details must be filled to the form for edit
I have a form which can submited.and have list,that listed all submited form details.我有一个可以提交的表单,并且有一个列表,其中列出了所有提交的表单详细信息。
I tried it in different ways.I want to fill the form with the corresponding details when I clicked the edit button.我尝试了不同的方法。我想在单击编辑按钮时用相应的详细信息填写表单。 Here is my php file
这是我的 php 文件
<div class="row">
<div class="col-sm-9">
<b>Leader Name : </b><?php echo($row["lead_name"]); ?><br>
<b>Phone Number : </b><?php echo($row["phone_number"]); ?><br>
<b>Email : </b><?php echo($row["email"]); ?><br>
<b>Part Created Time : </b><?php echo($row["create_date_and_time"]); ?>
<br>
</div>
<div class="col-sm-3 ">
<form role="form" action='index.php' method='POST'>
<input type='hidden' name='party_id' value='<?php echo($row["party_id"]); ?> '>
<input type="submit" class="btn btn-sm btn-success btn-block" id="edit" name="edit" value="Edit" style="font-size: 12px; padding: 3px;">
<input type="submit" class="btn btn-sm btn-danger btn-block" id="delete" name="delete" value="Delete" style="font-size: 12px; padding: 3px;">
</form>
<?php
if (isset($_POST['delete'])) {
print("<script> alert('delete'); </script>");
$party_id = isset($_POST['party_id']) ? $_POST['party_id'] : "";
$queryDelete = "DELETE FROM party_details WHERE party_id='$party_id'";
if ($conn->query($queryDelete)) {
$_SESSION['party'] = "";
$_SESSION['trips'] = [];
print("<script>
alert('Party removed');
window.location.href='../tripCreate';
</script>");
} else {
print("<script>alert('Error when remove ! ');</script>");
}
$_POST = array();
}
if (isset($_POST['edit'])) {
$party_id1 = isset($_POST['party_id']) ? $_POST['party_id'] : "";
$query1 = "SELECT * FROM party_details WHERE party_id='$party_id1'";
$result1 = $conn->query($query1);
$row1 = $result1->fetch_assoc();
}
?>
</div>
first of all, you should specify not only result you want to achieve, but also what kind of problem you are facing.首先,你不仅要说明你想要达到的结果,还要说明你面临什么样的问题。 is it php error, or information not being displayed in resulted page?
是 php 错误,还是结果页面中没有显示信息?
one thing i spotted is that you got $row1 = $result1->fetch_assoc();
我发现的一件事是你得到了
$row1 = $result1->fetch_assoc();
but in form you echo $row[]
(instead of $row1[]
), which i dont see being created anywhere.但是在形式上你回显
$row[]
(而不是$row1[]
),我没有看到它在任何地方被创建。
also, did you try var_dump($row)
in php and check its content (or $row1
...)?另外,您是否在 php 中尝试
var_dump($row)
并检查其内容(或$row1
...)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.