致命错误:在第19行调用dev/add_comment.php中未定义的函数redirect()


Fatal error: Call to undefined function redirect() in dev/add_comment.php on line 19

我不确定是重定向有问题还是其他行有问题这是我的文件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()既不是PHP函数,也不是脚本中定义的函数。如果您正在尝试重定向,请使用header():

header("location: dev/view_post.php?id='.$_GET['id'].'#post-'.mysql_insert_id()");
exit(); //note, I didn't test this for single/double quote accuracy, that's on you
$url = 'dev/view_post.php?id='.$_GET['id'].'#post-'.mysql_insert_id();
header('Location:'.$url);