正在尝试更新记录,但在php中失败
我试图通过$\u GET获取帖子的id来更新记录,然后通过$\u post更新记录 我已经通过$\u GET执行了删除操作,并且mysqli\u fetch\u assoc在显示记录以进行编辑时也可以正常工作,但实际编辑没有发生。空检查函数中的代码验证中出现空错误 我已经做了很多研究,但我似乎无法理解这个错误,如果有人能建议修改代码,我将不胜感激 提前谢谢你 这就是错误所在正在尝试更新记录,但在php中失败,php,post,mysqli,phpmyadmin,get,Php,Post,Mysqli,Phpmyadmin,Get,我试图通过$\u GET获取帖子的id来更新记录,然后通过$\u post更新记录 我已经通过$\u GET执行了删除操作,并且mysqli\u fetch\u assoc在显示记录以进行编辑时也可以正常工作,但实际编辑没有发生。空检查函数中的代码验证中出现空错误 我已经做了很多研究,但我似乎无法理解这个错误,如果有人能建议修改代码,我将不胜感激 提前谢谢你 这就是错误所在 Notice: Undefined index: id in /then the long url etc/ 下面是代码
Notice: Undefined index: id in /then the long url etc/
下面是代码
<?php
//DB Connection
include'include/db-conn.php';
if (isset($_POST['edit'])) {
//Raw GET Inputs
$raw_c_id = $_GET['id'];
//Cleaned Inputs
$c_c_id = filter_var($raw_c_id, FILTER_SANITIZE_STRING);
//Error Mwssages
$empty = '<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Error!</strong>Field is empty please provide content!
</div>
';
$success = '<div class="alert alert-success alert-dismissible fixed-top">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Success!</strong> Content Added Successfully
</div>
';
$not_success = '<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Not Success!</strong> Content Not Added Successfully
</div>
';
if (empty($c_c_id)) {
echo $empty;
exit();
header("Location:index.php");
}
$update = "UPDATE `continents`
SET `continent_name`='$c_c_name', `last_edited`='date(d/m/Y)'
WHERE `id`='$c_c_id'";
$run_update = mysqli_query($conn, $update);
if (!$run_update) {
header("Location: index.php");
echo $not_success;
}
else{
header("Location: index.php");
echo $success;
}
}
?>
看起来您正试图同时使用GET和POST参数。它不起作用的原因是提交表单时GET参数丢失。您需要在表单的action属性中传递它:
<form action="edit.php?id=<?php echo $_GET['id'] ?>" method="POST">
您可以发布它发布到的URL吗。我想看看GET Parameters如何显示您的实际url。非常感谢您的帮助,它确实起了作用。有没有机会从我这里看一下这个代码,让我知道我哪里弄错了!如果此答案解决了您的问题,请将其标记为正确答案。我会看看你的其他帖子。
<div class="table-responsive">
<table id="example" class="table table-hover ">
<thead>
<tr class="">
<th>ID</th>
<th>Continent Name</th>
<th>Date Added</th>
<th>Status</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$all_continents = "SELECT * FROM `continents` ORDER BY `status`";
$run = mysqli_query($conn,$all_continents);
while ($row_result = mysqli_fetch_assoc($run)) {
$id = $row_result['id'];
$c_continent_name = $row_result['continent_name'];
$c_date_added = $row_result['date_added'];
$c_status = $row_result['status'];
echo "
<tr>
<td>$id</td>
<td>$c_continent_name</td>
<td>$c_date_added</td>
<td>$c_status</td>
<td>
<a class='btn btn-info' href='edit.php?id=$id'>Edit</a>
</td>
<td>
<a class='btn btn-danger' href='delete.php?id=$id'>Delete</a>
</td>
</tr>
";
}
?>
</tbody>
</table>
<form action="edit.php?id=<?php echo $_GET['id'] ?>" method="POST">