how to solve this error I am creating php application in which i am trying to edit post
在我不确定我是否正确完成后显示错误我的用户部分工作正常但在管理部分我遇到了edit_post.php的问题
$ id = $ _GET ['id'];
它显示此行包含eror但是我无法找到之后我在此查询中使用此变量连接此$ id变量
$ query =“SELECT * FROM post WHERE id =”。$ id;
我认为这会造成一切混乱。
post是mysql中表的名称,它包含5个字段id,title,body,author,date
我正在尝试使用$ _GET变量获取id
SCREAM: Error suppression ignored for
Notice: Undefined index: id in C:\wamp\www\phpblog\admin\edit_post.php on line 4
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 139
<?php include 'includes/header.php' ;?>
<?php
// $id is line no. 4
$id = $_GET['id'];
$db = new Database();
// Create Query
$query="SELECT * FROM post WHERE id = ".$id;
// Running Query
$post=$db->select($query)->fetch_assoc();
// Creating Query For Categories
$query="SELECT * FROM categories";
$category=$db->select($query);
?>
<form role="form" method="post" action="edit_post.php">
<div class="form-group">
<label>Post Title</label>
<input nane="title" type="text" class="form-control" placeholder="Enter Title" value="">
</div>
<div class="form-group">
<label>Post Body</label>
<textarea name="body" class="form-control" placeholder="Enter The Text For The Body !"></textarea>
</div>
<div class="form-group">
<label>Category</label>
<select name="category" class="form-control">
<option>News</option>
<option>Events</option>
</select>
</div>
<div class="form-group">
<label>Author</label>
<input nane="author" type="text" class="form-control" placeholder="Enter Author Name">
</div>
<div class="form-group">
<label>Tags</label>
<input nane="tags" type="text" class="form-control" placeholder="Enter Tags">
</div>
<div>
<input name="submit" type="submit" class="btn btn-default" value="submit">
<a href="index.php" class="btn btn-default">Cancel</a>
<input name="delete" type="submit" class="btn btn-danger" value="delete">
</div>
<br>
</form>
<?php include 'includes/footer.php';?>
答案 0 :(得分:0)
您需要使用get参数id
调用您的网页。您收到此错误,因为未设置此参数。
?id=42
例如
domain.com/index.php?id=42
替代方案,您可以提供一些默认ID:
$defaultId = 1;
$id = isset($_GET['id']) ? $_GET['id'] : $defaultId;
或者说,对不起,错误的参数:
if (isset($_GET['id'])) {
$id = $_GET['id'];
//Work with $id
} else {
//Error Handling
echo '<p>An Error is occured (Sorry, but wrong Parameter)</p>';
}