形式 - 未定义指数误差PHP

问题描述:

how to solve this error I am creating php application in which i am trying to edit post 

我不肯定后,我是否做得正确与否它显示的错误我的用户部分工作正常,但在管理部分我有与edit_post.php问题形式 - 未定义指数误差PHP

$ id = $ _GET ['id'];

它显示此行包含eror,但我没能找到后,我有串联在一个SQL查询这个$ id变量与此变量

$查询=“SELECT * FROM帖子里。ID =” $ ID;

我认为这是造成所有的混乱。

职位是在MySQL表的名称,它包含5个字段ID,标题,正文,作者,日期

我试图获取与$ _GET变量

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

我不知道它在哪里是否是重复的问题,但我要求协议ing我的应用程序,我不是在这里得到积分和类似的东西 – 2014-08-30 12:00:47

你的id需要使用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>'; 
} 
+0

谢谢克里斯蒂安它通过isset($ _ GET ['id'])工作 – 2014-08-30 12:01:27