【问题标题】:Can't find the error :/找不到错误:/
【发布时间】: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,因为你是通过&lt;a&gt; 而不是通过提交表单来定向到crud/update.php
  • 找不到错误 404 页面
  • 您正在混合使用 HTML 和 PHP,链接应该是:&lt;a href="crud/update.php?id=&lt;?php echo $r['id'] ?&gt;"&gt;Edit&lt;/a&gt;&lt;/td&gt;
  • @kerrysun 答案能解决您的问题吗?如果是,请接受答案并关闭问题。

标签: php database mysqli error-handling syntax


【解决方案1】:

您收到 404 的原因是您没有正确的链接。

你在网上混合了 HTML 和 PHP

<a href="crud/update.php?id='.$r['id'].'">Edit</a>

应该是:

<a href="crud/update.php?id=<?php echo $r['id'] ?>">Edit</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 2012-12-29
    • 2013-11-24
    • 2011-09-20
    • 2017-09-21
    • 2015-02-08
    相关资源
    最近更新 更多