我已經創建了一個名爲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