2013-06-26 22 views
0

我決定離開所有代碼,以免讓那些看到這一點的人感到困惑。

在線#57,這個頁面上的唯一窗體,我試圖$ _POST ID等於post_iD。 除了post_iD之外,一切都正確地上傳到MySQL。

我總是得到一個通知:未定義的索引:post_iD上$ post_iD = $ _POST ['post_iD'];在if(isset($ POST ['comment']))中。

我確定問題在於我如何檢索表單內的post_iD,而不是任何與PDO有關的問題,但是因爲PDO數據正在正確插入,除了我提到的post_iD。

我使用post_iD從數據庫循環帖子,它除了在窗體內工作,任何啓發這個問題?

代碼如下。

if(isset($_POST['comment'])){ 
    $comment = $_POST['comment']; 
    $post_iD = $_POST['post_iD']; 
    $data  = $Wall->Insert_Comment($uiD, $post_iD, $comment, $_SERVER['REMOTE_ADDR']); 
} 

if ($updatesarray){ 
    foreach ($updatesarray as $data){ 
     $post_iD = $data['post_iD']; 
     $orimessage = $data['message']; 
     $message = tolink(htmlcode($data['message'])); 
     $time  = $data['created']; 
     $mtime  = date("g:i", $time); 
     $username = $data['username']; 
     $uploads = $data['uploads']; 
     $uiD  = $data['uid_fk']; 
?> 
<div class="wrap"> 
    <div class="item" id="stbody<?php echo $post_iD;?>"> 
     <div class="loop-post"> 
      <div class="loop-post-content"> 
       <div class="loop-post-image"> 
        <a href="" class="post-link"> 
         <?php 
          if ($uploads){ 
           $s = explode(",", $uploads); 
            foreach ($s as $a){ 
             $newdata = $Wall->Get_Upload_Image_Id($a); 
             if ($newdata) echo "<a href='uploads/" . $newdata['image_path'] . "' rel='facebox'> 
              <img src='uploads/" . $newdata['image_path'] . "' width='520' height='245' class='imgpreview attachment-top_story_post wp-post-image' /></a>"; 
            } 
           echo "</div>"; 
          } 
         ?> 
        </a> 
      </div> 
      <div class="loop-post-byline">By <a rel="author" title="Posts by Emil Protalinski" href=""><?php echo $username;?></a> 
       <span class="date"><a href='<?php echo $base_url ?>status/<?php echo $post_iD; ?>'title='<?php echo $time;?>' class="timeposted"> — <?php echo $mtime;?></a></span> 
      </div> 
      <a class="post-link">       
       <?php echo clear($message);?> 
      </a> 

      <div class="post_comment"> 
       <?php $x=1; include_once 'load_comments.php'; ?> 

       <div class="commentupdate" id="commentbox<?php echo $post_iD;?>"> 
        <div class="stcommentimg"> 
         <img src="<?php echo $photo;?>" class="small_face"> 
        </div> 

        <div class="stcommenttext"> 
         <form method="POST" action=""> 
          <textarea name="comment" class="comment" id="<?php echo $post_iD;?>" value="<?php echo $post_iD;?>"></textarea> #57 
          <input type="submit" value="comment"> 
         </form> 
        </div> 
       </div> 

      </div> 
     </div> 
    </div> 
</div> 

<?php } } else echo '<h3 id="noupdates">No Updates!</h3>';?> 

回答

1

你需要做到這一點...

<textarea name="comment" class="comment" id="comment-<?php echo $post_iD;?>"></textarea> 
<input type="hidden" id="post_iD" name="post_iD" value="<?php echo $post_iD;?>" /> 

您選擇的Cuz從來沒有經過任何地方POST_ID ....這將通過它隱藏表單...

,值對於你的textarea不會是$ post_iD,它可能是一些類型的評論/帖子....我假設你只是有調試

+0

太簡單了,我打算試試,但我忘了。感謝您的快速和完美的迴應,這將爲我清除很多時間。我感謝你的時間和迴應! – iBrazilian

+0

是的,它的工作,我忘了接受它。再次感謝你。 – iBrazilian

2

你永遠不會在任何地方設置post_iD變量。如果你想在$_POST數組中使用它,你需要首先在表單中設置它。

<form method="POST" action=""> 
    <input type="hidden" name="post_iD" value="<?php echo $post_iD; ?>" /> 
    <textarea name="comment" class="comment" id="<?php echo $post_iD;?>" value="<?php echo $post_iD;?>"></textarea> #57 
    <input type="submit" value="comment"> 
</form>