我已经创建了一个名为profile.php的页面,通过使用“get”方法从mainpage.php获取值。但是,如果从mainpage.php发送的值为空或错误,则页面将重定向到mainpage.php。不过,我在profile.php中使用了“post”方法,允许用户在profile.php中发布内容。所以,如果用户提交的东西,profile.php重新加载和重新加载profile.php使变量,我从mainpage获得,为空,并指示页面不主页page.php不情愿。我可以如何解决它?代码;Post方法阻止页面加载
$another_user = $_GET['username'];//gets a value from mainpage.php
$check = mysql_query("SELECT * FROM users WHERE user_name = '".$another_user."'");
$sent = mysql_fetch_array($check);
if(!$sent)
{
header('Location: mainpage.php');
exit();
}
//some codes around here
<form action="profile.php" method="post">
Commet: <input type="text" name="comment" placeholder = "comments?"/>
<input type="submit"/>
</form>
<?php
if(isset($_POST['comment'])&&!($_POST['comment']=""))
{
$writing = $_POST['comment'];
echo $writing;
}
感谢
你知不知道你是在你的SQL查询结束时丢失了“还有,看到整个文件会更有帮助,而不仅仅是这个片段。 – Prisoner
我不同意,囚徒。他的代码片段足以证明他的问题。错过了一个“,正如我在我的回答中指出的那样。 – Jules
是的,我意识到:(但实际上,我把它翻译成英文时意外地使它变得更有意义。代码在语法方面很好,但除了问题中提到的问题:) – user893970