试图制作一个crud函数/联系人列表。用户在登录后会被带到此页面:

通过点击编辑功能,我希望带用户到一个允许他们编辑联系人详细信息的页面。目前还在努力使链接功能正常运行。
链接照片是我的/view文件。看起来是这样的:
<?php
session_start();
if(isset($_SESSION['u_uid'])){
$uid = $_SESSION['u_id'];
require_once('connect.php');
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);
?>
<head>
<title>Motoko</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th><strong>Name</strong></th>
<th><strong>Company</strong></th>
<th><strong>Title</strong></th>
<th><strong>Phone</strong></th>
<th><strong>Email</strong></th>
<th><strong>Address</strong></th>
<th><strong>Extras</strong></th>
</tr>
<?php
while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td><?php echo $r['Name']; ?></td>
<td><?php echo $r['Company']; ?></td>
<td><?php echo $r['Title']; ?></td>
<td><?php echo $r['Phone']; ?></td>
<td><?php echo $r['Email']; ?></td>
<td><?php echo $r['Address']; ?></td>
<td><a href="crud/update.php?id=<?php echo $r['id'] ?>">Edit</a></td>
<td><input type="button" onClick="deleteme(<?php echo $r['u_uid']; ?>)" name="Delete" value="Delete"></td>
</tr>
<!-- Javascript function for deleting data -->
<script language="Javascript">
function deleteme(delid)
{
if(confirm("Are you sure you want to Delete?")){
window.location.href='crud/delete.php';
}
}
</script>
<?php } ?>
</table>
</div>
</body>
</html>
<?php
}else{
header("Location: http://motoko.sorainsurance.com.au");
}
?>这将把它们带到/update文件中。开头是这样的:
<?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']);
$comp = mysqli_real_escape_string($connection,$_POST['comp']);
$title = mysqli_real_escape_string($connection,$_POST['title']);
$phone = mysqli_real_escape_string($connection,$_POST['urstel']);
$email = mysqli_real_escape_string($connection,$_POST['email']);
$location = mysqli_real_escape_string($connection,$_POST['location']);
$UpdateSql = "UPDATE `contact` SET Name='$name', Company='$comp',
Title='$title', Phone='$phone', Email='$email', Address='$location' WHERE id=$id";
$res = mysqli_query($connection, $UpdateSql);
if($res){
echo $smsg = "Successfully updated data.";
echo header('location: view.php');
}else{
echo $fmsg = "Failed to update data.";
}
}知道为什么这个错误会不断出现吗?如此困惑和挣扎的前进:
非常感谢!
发布于 2018-02-05 03:48:28
404错误代码表明,您没有请求正确的URL。
这将把它们带到/update文件中。
您已经提到,请求将转到update文件,但您的请求URL是crud/update.php。
现在,请求URL取决于文件的相关性。那么,您是在根文件夹中查看文件,还是在crud文件夹下查看crud文件呢?
==Edited==
(参考您最近的评论)看起来,您的update.php和view.php存在于同一个文件夹中,那么您应该简单地更改请求
crud/update.php至
update.php您不需要在请求中提到文件夹路径。
https://stackoverflow.com/questions/48615575
复制相似问题