未定义的变量:C:\ xampp \ htdocs中的id

时间:2016-12-30 22:43:27

标签: php mysqli

我正在尝试更新数据库中的记录,但是我收到此错误Notice: Undefined variable: id in C:\xampp\htdocs\test\admin\admin\update.php on line 15尝试了POST和GET方法,但仍然收到错误。

这是我的代码:

<?php
session_start();
//Include database connection details
include('dbconnect.php');
{   
    if(isset($_GET['id']))
        $id = mysqli_real_escape_string($_POST['id']);  

    $title =  ($_POST['title']);
    //$cname = ($_POST['txtEditor']);
    //$cat = strip_tags($_POST['cat']);
    //$date=date("Y-m-d");

    $sql =("UPDATE newsarticles SET  headline='$title'  WHERE ID='$id'");


    if ($conn->query($sql) === TRUE) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . $conn->error;
    }
}
$conn->close();
//$results = $mysqli->query("UPDATE products SET product_name='52 inch TV', product_code='323343' WHERE ID=24");
?>

这是我的表格

  <?php
session_start();
include("dbconnect.php");


 if(isset($_GET['id']))
    $id = strip_tags($_GET['id']);
$sql = "SELECT * FROM newsarticles WHERE id=$id" ;
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result))

    {
        $image= $row['photo'];
    $title = $row['headline'];
    $description = ( $row['text']);
    $time = $row['publishDate'];
    }
?>
<link href="plugins/WYSIWYG/editor.css" type="text/css" rel="stylesheet"/>
<script src="plugins/WYSIWYG/editor.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#txtEditor").Editor();
        $("#txtEditor").Editor("setText", <?php echo json_encode($description) ;?>);
    });
    </script>


<form name="my_form" action="update.php" method="POST"  enctype="multipart/form-data">
  <div class="form-group">
    <label for="exampleInputEmail1">Date</label>
    <input type="text" class="form-control" id="time" name="time"  value="<?php echo date('d-m-Y'); ?>" disabled>
    <small id="emailHelp" class="form-text text-muted"></small>
  </div>
  <div class="form-group">
    <label>Article Title</label>
    <input type="text" class="form-control" id="title" name="title" value="<?php echo $title; ?>" placeholder="title" required />
  </div>
  <div class="form-group">
    <label >select categories</label>
    <select class="form-control" id="cat" name="cat">
      <option value="World">World</option>
 <option value="Sport">Sport</option>
 <option value="Politics">Politics</option>
 <option value="Business">Business</option>
 <option value="Technology">Technology</option>
 <option value="Entertainment">Entertainment</option>
 <option value="Fashion">Fashion</option>
 <option value="Gist">Gist</option>    </select>
  </div>

  <div class="form-group">
    <label>Write Article </label>
    <textarea class="form-control" id="txtEditor" name="txtEditor"></textarea>
  </div>
  <div class="form-group">
    <label for="exampleInputFile">upload image</label>
    <input type="file" accept="image/*" name="myimage" id="myimage" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
    <small id="fileHelp" class="form-text text-muted"></small>

  </div>

  <button onclick=" $('#txtEditor').val($('.Editor-editor').html());" type="Publish" id="Publish" name="Publish" class="btn btn-primary">Publish</button>
</form>

以上代码是我的表单页面,其中包含php代码,用于显示各自字段中数据库的值

请帮忙吗?

0 个答案:

没有答案