【发布时间】:2018-01-25 05:48:05
【问题描述】:
得到一张包含客户数据的表格。试图合并一个编辑功能。目前,该表有一个<a href> 用于“编辑”链接。
<tr>
<th><strong>Extras</strong></th>
</tr>
<?php while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td><a href="crud/update.php?id='.$r['id'].'">Edit</a></td>
<td><input type="button" onClick="deleteme(<?php echo $r['u_uid']; ?>)" name="Delete" value="Delete"></td>
</tr>
function deleteme(delid)
{ if(confirm("Are you sure you want to Delete?")){
window.location.href='crud/delete.php';
}
}
</script>
<?php } ?>
注意:
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);
我希望将用户带到 crud/update.php 开头:
<?php
error_reporting();
require_once('connect.php');
$id = $_GET['id'];
$SelSql = "SELECT * FROM `contact` WHERE id=$id";
$res = mysqli_query($connection, $SelSql);
$r = mysqli_fetch_assoc($res);
if(isset($_POST) & !empty($_POST)){
$name = mysqli_real_escape_string($connection,$_POST['name']);
//and other credentials
$UpdateSql = "UPDATE `contact` SET Name='$name', Company='$comp',
Title='$title', Phone='$phone', Email='$email', Address='$location' WHERE id=$id";
拔掉我的头发,因为我找不到每次按“编辑”链接时都会出错的原因。
干杯,伙计们。
【问题讨论】:
-
错误信息是什么?
-
我认为你应该在
if()中检查$_GET而不是$_POST,因为你是通过<a>而不是通过提交表单来定向到crud/update.php -
找不到错误 404 页面
-
您正在混合使用 HTML 和 PHP,链接应该是:
<a href="crud/update.php?id=<?php echo $r['id'] ?>">Edit</a></td> -
@kerrysun 答案能解决您的问题吗?如果是,请接受答案并关闭问题。
标签: php database mysqli error-handling syntax