我决定保留所有代码,以免让看到此内容的人感到困惑。
在第 57 行,此页面上的唯一表单,我试图 $_POST 等于 post_iD 的 id。除了 post_iD 之外,所有内容都正确上传到 MySQL。
我总是收到一条通知:未定义的索引:$post_iD = $_POST['post_iD']; 上的 post_iD 在 if(isset($POST['comment'])) 中。
我确定问题在于我如何尝试在表单中检索 post_iD,而不是 PDO 的任何问题,而是 html 作为 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>';?>