【发布时间】:2019-04-02 11:49:05
【问题描述】:
我试图通过 $_GET 获取帖子的 id 来更新记录,然后通过 $_POST 更新记录。
我已经通过 $_GET 执行了删除操作,它也可以正常工作,mysqli_fetch_assoc 也可以很好地显示要编辑的记录,但实际编辑没有发生,它在空检查功能的代码验证中给出了空错误.
我已经进行了大量研究,但似乎无法解决这个错误,如果有人可以建议对代码进行任何更改,我将非常感谢。
提前谢谢你!
这是错误
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;
}
}
?>
这是html部分
<div class="panel-body">
<form action="edit.php" method="POST">
<div class="form-group">
<label for="continent_name">Continent Name</label>
<input required type="text" placeholder="10" class="form-control" value="<?php echo $c_name ; ?>" name="continent_name">
</div>
<small>Date Added: <?php echo $c_dated_added ; ?></small> / <small>Last Edited: <?php echo $c_last_edited ; ?></small>
<div class="form-group">
<input class="form-control btn-success" type="submit" name="edit" value="Submit">
</div>
</form>
</div>
使用 while 循环
<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>
【问题讨论】:
-
你能发布它发布到的 URL。我想查看 GET 参数
-
显示您的实际网址。
标签: php post mysqli phpmyadmin get