【发布时间】:2013-12-04 02:43:21
【问题描述】:
我不确定我是否只是在重定向或其他一些行有问题 所以这是我的文件 add_comment.php
<?php
include ('connection.php');
$id = $_GET['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$content = $_POST['content'];
$date = date('F j<\s\up>S</\s\up>, Y');
//$expire = time()+60*60*24*30;
//setcookie('name', $_POST['name'], $expire, '/');
//setcookie('email', $_POST['email'], $expire, '/');
//setcookie('website', $_POST['website'], $expire, '/');
mysql_query("INSERT INTO blog_comments (post_id,name,email,website,content,date) VALUES ('".$id."', '".$name."', '".$email."', '".$website."', '".$content."', '".$date."')");
mysql_query("UPDATE blog_posts SET num_comments=num_comments+1 WHERE id='$id' LIMIT 1");
redirect('dev/view_post.php?id='.$_GET['id'].'#post-'.mysql_insert_id());
?>
post_view.php
<?php
// post_view.php
include ('connection.php');
//get id from the link
$id = $_GET['id'];
$query = "SELECT * FROM blog_posts WHERE id = '$id'";
$result = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_assoc($result))
{
echo '<h2>'.$row['title'].'</h2>';
echo '<em>Posted '.date('F j<\s\up>S</\s\up>, Y', $row['date_posted']).'</em><br/>';
echo nl2br($row['post_content']).'<br/>';
echo '<a href="dev/edit_post.php?id='.$_GET['id'].'">Edit</a> | <a href="dev/delete_post.php?id='.$_GET['id'].'">Delete</a> | <a href="dev/blog.php">View All</a>';
}
//comments section
echo '<hr/>';
$query2 = "SELECT * FROM blog_comments where post_id = '$id' ORDER BY date ASC";
$result2 = mysql_query($query2) or die (mysql_error());
while ($row2 = mysql_fetch_assoc($result2)) {
echo $row2['name'];
}
echo '</ol>';
echo <<<HTML
<form method="post" action="dev/add_comment.php?id={$_GET['id']}">
<table>
<tr>
<td><label for="name">Name:</label></td>
<td><input name="name" id="name"/></td>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td><input name="email" id="email"/></td>
</tr>
<tr>
<td><label for="website">Website:</label></td>
<td><input name="website" id="website"/></td>
</tr>
<tr>
<td><label for="content">Comments:</label></td>
<td><textarea name="content" id="content"></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Post Comment"/></td>
</tr>
</table>
</form>
HTML;
?>
一定是什么问题? 我是 php 新手。多谢你们 我收到错误“致命错误:在第 19 行的 dev/add_comment.php 中调用未定义函数 redirect()”
【问题讨论】: