PHP挣扎。错误404

时间:2018-02-05 03:40:06

标签: php mysql error-handling edit crud

尝试制作一个crud功能/联系人列表。用户登录后将被带到此页面:

只需单击编辑功能,我希望将用户带到允许他们编辑联系人详细信息的页面。目前正在努力使链接功能正常。

链接照片是我的/查看文件。看起来像这样:

<?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.";
    }
}

知道为什么错误不断出现?如此困惑和努力进步:(

非常感谢!

1 个答案:

答案 0 :(得分:0)

404错误代码表示您的请求不正确URL

  

然后将它们带到/ update文件

您提到,请求将转到update文件,但您的请求URLcrud/update.php

现在,请求URL取决于文件的相关性。那么,您是否在根文件夹和update.php文件夹下的crud查看文件?

<强> ==被修改==

(参考您的最新评论)好像,您的update.phpview.php存在于同一个文件夹中,那么您只需更改请求

crud/update.php

update.php

您无需在请求中提及文件夹路径。