簡體   English   中英

提交表單后如何清除頁面內容?

[英]How do I clear the page content after a form is submitted?

我的項目中目前有以下代碼:

require_once('mysql.inc.php');
session_start();

if (!isset($_SESSION['username']) && !isset($_SESSION['uid']))
{
    login_sequence();
}
else
{
    login_check($_SESSION['username'], $_SESSION['uid']);
}

function login_sequence()
{
    echo '<p>' . $pretext . '</p><form method="post" action="" /><label for="password">Password: </label><input type="password" name="password" id="password" /><input type="submit" value="Log In" /><input type="hidden" name="submitted" /></form>';
    if (isset($_POST['submitted']))
    {
        $pword = hash('sha256', $_POST['password']);
        $query = "SELECT pword FROM users WHERE user = 'guest'";
        $result = mysql_query($query);
        $return = mysql_fetch_assoc($result);
        if ($return['pword'] == $pword)
        {
            pageout();
        }
        else
        {
            echo 'You entered the wrong password, if you are not a member, please leave.';
        }
    }
}

function login_check($username, $uid)
{
}

function pageout()
{
    echo('
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en-US">
        <head>
            <title></title>
            <link rel="stylesheet" type="text/css" href="" />
        </head>
        <body>
            <div id="header">
            <p>WOOT</P>
            </div>
            <div id="">
            </div>
            <div id="navigation">
            </div>
            <div id="footer">
            </div>
        </body>
    </html>
    ');
}

?>

數據庫中存儲有一個“來賓”密碼,它可以訪問數據庫並對照數據庫中存儲的用戶密碼來檢查用戶輸入的密碼。 我想擁有它,以便在提交表單並且信息正確之后,在同一頁面上表單消失並且出現頁面。 我該怎么做? 如何刪除表格以便為新頁面騰出空間?

標頭(位置...)成功,或以登錄設置為條件的頁面顯示

簡單地做

在表格的結尾和php代碼中執行此操作

  if(!isset($_POST['s'])){ ?> your form here <?php } else //form handle 

我將使結構看起來略有不同:

//First
if (!isset($_POST['submitted'])) {
    //include your form only
} else {
    //Check if user submitted correct password

   //If password is correct
   if ($return['pword'] == $pword) {
       pageout();
       //OR write pageout code on different page and call header("Location: Yourpage.php");
   } else {
       //Include form or inform user about password mismatch
   }  
}

編輯。 另外,如果您使用header(“ Location:”)函數,請確保沒有回顯或包含任何輸出數據的內容。 這將導致標題已發送錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM