gpt4 book ai didi

php - fatal error : Call to undefined function redirect() in dev/add_comment. php 第 19 行

转载 作者:行者123 更新时间:2023-11-29 08:17:13 29 4
gpt4 key购买 nike

我不确定我是否只是遇到重定向问题或其他一些线路问题这是我的文件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 新手。多谢你们我收到错误“ fatal error :在第 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

关于php - fatal error : Call to undefined function redirect() in dev/add_comment. php 第 19 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20365830/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com