试图更新记录,但在PHP失败

时间:2018-10-29 14:10:16

标签: php post mysqli phpmyadmin get

尝试通过$ _GET获取帖子的ID来更新记录,然后通过$ _POST更新记录。

我已经通过$ _GET执行了删除操作,它也可以正常工作,而且mysqli_fetch_assoc也可以很好地显示要编辑的记录,但是实际的编辑没有发生,它通过空检查功能中的代码验证给出了一个空错误。

我已经进行了大量研究,但似乎无法解决该错误,如果有人可以建议对代码进行任何更改,我将表示感谢。

提前谢谢!

这是错误

void post(const char *pre, const char *in,  char *pos,int n) {
   /* some code*/
}

下面是代码

Notice: Undefined index: id in /then the long url etc/

这是html部分

<?php
 //DB Connection
  include'include/db-conn.php';
  if (isset($_POST['edit'])) {
     //Raw GET Inputs
    $raw_c_id       = $_GET['id'];

    //Cleaned Inputs
    $c_c_id         = filter_var($raw_c_id, FILTER_SANITIZE_STRING);

    //Error Mwssages
    $empty      = '<div class="alert alert-danger alert-dismissible">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>Error!</strong>Field is empty please provide content!
              </div>
              ';
    $success    = '<div class="alert alert-success alert-dismissible fixed-top">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>Success!</strong> Content Added Successfully
              </div>
              ';
    $not_success  = '<div class="alert alert-danger alert-dismissible">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong>Not Success!</strong> Content Not Added Successfully
                  </div>
                  ';

      if (empty($c_c_id)) {
        echo $empty;
        exit();
        header("Location:index.php");
      }

      $update      = "UPDATE `continents` 
       SET `continent_name`='$c_c_name', `last_edited`='date(d/m/Y)'  
       WHERE `id`='$c_c_id'";
       $run_update  = mysqli_query($conn, $update);
      if (!$run_update) {
        header("Location: index.php");
        echo $not_success;

      }
      else{
        header("Location: index.php");
        echo $success;
      }
  }
 ?>

这是while循环

<div  class="panel-body">
            <form action="edit.php" method="POST">
                <div class="form-group">
                  <label for="continent_name">Continent Name</label>
                  <input required type="text" placeholder="10" class="form-control" value="<?php echo  $c_name ; ?>" name="continent_name">
                </div>
              <small>Date Added: <?php echo  $c_dated_added ; ?></small> / <small>Last Edited: <?php echo  $c_last_edited ; ?></small>
                <div class="form-group">
                  <input class="form-control btn-success" type="submit" name="edit" value="Submit">
                </div>
              </form>
          </div>

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试同时使用GET和POST参数。它不起作用的原因是因为提交表单时GET参数丢失。您需要将其传递给表单的action属性:

<form action="edit.php?id=<?php echo $_GET['id'] ?>" method="POST">

也请看看这篇文章中的建议: Is there a way to use GET and POST together?