【问题标题】:Fatal error: Call to undefined function redirect() in dev/add_comment.php on line 19致命错误:在第 19 行的 dev/add_comment.php 中调用未定义函数 redirect()
【发布时间】: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()”

【问题讨论】:

    标签: php mysql redirect


    【解决方案1】:

    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
    

    【讨论】:

    • 我必须创建一个函数并将该代码放入函数中吗?
    • 它不会自行创建 ;)
    • 祝兄弟好运,希望对您有所帮助!
    【解决方案2】:
    $url = 'dev/view_post.php?id='.$_GET['id'].'#post-'.mysql_insert_id();
    header('Location:'.$url);
    

    【讨论】:

    • 回答是一回事,解释是另一回事。解释了更好的答案。只是提醒:)
    • 每个人都会按照她自己的方式..你按照自己的方式回答问题,另一件事你只是关注别人的回答..不要为别人辩护
    • 证明?我给了一个友好的提示,你把它扭曲成冒犯了你的东西。你做你想做的事,我只是想帮你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 2012-04-21
    相关资源
    最近更新 更多