2014-08-29 61 views
-5
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

回答

0

你的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