2014-02-06 28 views
0

我的編輯頁面無法正常工作。我一直在收到 注意:未定義的變量。如果我把形式關閉每日新聞的形式只是disappers當我點擊更新按鈕我的編輯頁面無法正常工作

注意:未定義的變量:POST_TITLE在C:\ WAMP \ WWW \說服\ ADMIN \上線edit_posts.php 57

0down voteaccept

我必須說實話我很新的PHP。實際上,這段代碼來自我正在遵循的教程http://www.youtube.com/watch?v=oZ2KZRHASdQ。不幸的是視頻凍結前6分鐘,這就是爲什麼我要求幫助

我所做的是

<?php } } ?> 

看來,當我編輯的帖子到現在工作

但現在我得到這個錯誤

注意:未定義的索引:edit_form在C:\ wamp \ www \ Persuasion \ admin \ edit_posts.php在線96

再次我要感謝大家誰幫助

<html> 
       <head> 
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
       <link rel="stylesheet" href="admin_style.css" media="all"/> 
       <title>Admin Panel</title> 
       </head> 

       <body> 
       <div id="header"> 
       <a href="index.php"> 
       <h1>Welcome To Admin Panel</h1></div></a> 

       </div> 

       <div id id="sidebar"> 
       <h2><a href="#">Logout</a></h2> 
       <h2><a href="view_posts.php">View Posts</a></h2> 
       <h2><a href="insert_post.php">Insert New Posts</a></h2> 
       <h2><a href="#">View Comments</a></h2> 

       </div> 
       <?php 
       include("includes/connect.php"); 

       if (isset($_GET['edit'])) { 

        $edit_id = $_GET['edit']; 

        $edit_query = "select * from posts where post_id = '$edit_id'"; 

        $run_edit = mysql_query($edit_query); 

        while ($edit_row = mysql_fetch_array($run_edit)) { 

         $post_id = $edit_row['post_id']; 
         $post_title = $edit_row['post_title']; 
         $post_author = $edit_row['post_author']; 
         $post_keywords = $edit_row['post_keywords']; 
         $post_image = $edit_row['post_image']; 
         $post_content = $edit_row['post_content']; 

         ?> 

       <form method="post" action="edit_posts.php" enctype="multipart/form-data"> 

           <table width="600" align="center" border="10" bgcolor="brown"> 

           <tr> 
            <td align="center" bgcolor="yellow" colspan="6"><h1>Edit The Post Here</h1></td> 
           </tr> 

           <tr> 
            <td align="right">Post Title:</td> 
            <td><input type="text" name="title" size="35" value="<?php echo $post_title; ?>"></td> 
           </tr> 

            <tr> 
            <td align="right">Post Author:</td> 
            <td><input type="text" name="author" size="35" value="<?php echo $post_author; ?>"></td> 
           </tr> 

            <tr> 
            <td align="right" >Post Keywords:</td> 
            <td><input type="text" name="keywords" size="35" value="<?php echo $post_keywords; ?>"></td> 
           </tr> 

            <tr> 
            <td align="right">Post Image:</td> 
            <td> 
            <input type="file" name="image"> 
            <img src = "../images/<?php echo $post_image; ?>" height="56.25" width="75"></td> 
           </tr> 

            <tr> 
            <td align="right" >Post Content:</td> 
            <td><textarea name="content" cols="30" rows="15"/><?php echo $post_content; ?></textarea></td> 
           </tr> 

            <tr> 
            <td align="center" colspan="6"><input type="submit" name="update" value="Update Now"/></td> 
           </tr> 

           </table> 

       </form> 

<?php }} ?> 

       </body> 
       </html> 

       <?php 

       if (isset($_POST['update'])){ 

        $update_id = $_GET['edit_form']; 
        $post_title1 = $_POST['title']; 
          $post_date1 = date('m-d-y'); 
          $post_author1 = $_POST['author']; 
          $post_keywords1 = $_POST['keywords']; 
          $post_content1 = $_POST['content']; 
          $post_image1 = $_FILES['image']['name']; 
          $image_tmp = $_FILES['image']['tmp_name']; 

        if ($post_title1=='' or $post_author1=='' or 
        $post_keywords1=='' or $post_content1=='' or 
        $post_image1=='') { 

        echo "<script>alert ('Any of the fields are empty')</script>"; 
        exit(); 
        } 

        else { 

        move_uploaded_file($image_tmp,"../images/$post_image1"); 

        $update_query = "update posts set post_title=' 
        $post_title1', post_date='$post_date1',post_author='$post_author1', post_image='$post_image1', post_keywords='$post_keywords1', post_content='$post_content1' where post_id='$update_id'"; 

        if(mysql_query($update_query)) { 

        echo "<script>alert('Post has been updated')</script>"; 

       echo "<script>window.open('view_posts.php','_self')</script>"; 
        } 
       } 
       } 


       ?> 

回答

0

看來你的數據庫查詢沒有返回任何結果。因此$ post_title變量沒有被設置,你會得到未定義的變量錯誤。檢查查詢是否按預期工作。當你達到

1

POST_TITLE被設置好的此:

isset($_GET['edit']) 

檢查你如何存取權限那裏,你querys

編輯:

$edit_query = "select * from posts where post_id = '$edit_id'"; 

您的意思是:

$edit_query = "select * from posts where post_id = '".$edit_id."'"; 
0

您應該在表格之後關閉if (isset($_GET['edit'])) {,因爲表格在沒有該信息的情況下無法運行。我還會將POST處理放在頂部,這樣如果無法處理表單,則可以顯示具有預填充值和錯誤消息的相同表單。

除此之外,您還應該添加一些錯誤處理,以防未找到行編輯。

最後,您應該切換到PDO或mysqli ans準備語句,因爲mysql_*函數已被棄用,並且您現在有一個嚴重的sql注入問題。

0
<form method="post" action="edit_posts.php?edit_forms=<?php echo $post_id; ?>" enctype="multipart/form-data"> 

我認爲這將有利於