請用這個註冊表單幫我解決問題。很明顯,我的PHP腳本中有幾個錯誤。我的HTML形式如下:用PHP註冊表格
<form action="script_1.php" method="post">
<label for="name">Username:</label>
<input type="text" name="name" />
<label for="email">Email:</label>
<input type="text" name="email" />
<input type="submit" value="Register" />
</form>
和我的PHP腳本的樣子:
<?php
// Initialize session data
session_start();
/*
* If the user is already registered, display a
* message letting them know.
*/
if(isset($_SESSION['username'])) {
echo "You're already registered as" .$_SESSION[username]; // Corrected on Stack Overflow
}
// Checks if the form was submitted
else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/*
* If both the username and email fields were filled
* out, save the username in a session variable and
* output a thank you message to the browser. To
* eliminate leading and trailing whitespace, we use
* trim() function.
*/
$uname = isset($_POST['username']) ? trim($_POST['username']) : ''; // Corrected on Stack Overflow
$email = isset($_POST['email']) ? trim($_POST['email']) : ''; // Corrected on Stack Overflow
if(!empty($uname) && !empty($email)) { // Corrected on Stack Overflow
$_SESSION['username'] = $uname;
echo "Thanks for registering! <br />",
"Username: $uname <br />",
"Email: $email <br />";
}
/*
* If the user did not fill out both fields, display
* a message letting them know that both fields are
* required for registration.
*/
else {
echo "Please fill out both fields! <br />";
}
}
// If the form was not submitted, displays the HTML form
else {
?>
<?php } ?>
我需要它來檢查,如果輸入字段包含的東西,然後執行操作。如果在這些字段中沒有插入任何內容,我還需要它來執行不同的功能。
你的表單字段'name'不符合您的PHP這是尋找'username'。 –
哦,我的話......對不起。我花了8小時學習PHP,現在我已經死了,但主要是,謝謝你的一切。你救了我... – Mosire