代码之家  ›  专栏  ›  技术社区  ›  kerry sun

PHP陷入困境。错误404

  •  0
  • kerry sun  · 技术社区  · 7 年前

    正在尝试创建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"); 
    
    }
    
    ?>
    

    这将把它们带到/更新文件。开头是这样的:

     <?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 回复  |  直到 7 年前
        1
  •  0
  •   Ravi    7 年前

    404 错误代码表明,您的请求不正确 URL .

    这将把他们带到/更新文件

    您提到,请求将转到 update 文件,但您的请求 统一资源定位地址 crud/update.php .

    现在,请求 统一资源定位地址 取决于文件的相对性。所以,是否查看根文件夹中存在的文件,以及 update.php 在下面 crud 文件夹

    ==已编辑==

    (参考您的最新评论)似乎 使现代化php view.php 存在于同一文件夹中,那么您只需更改请求

    crud/update.php
    

    update.php
    

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