[英]I am coding a login page with HTML and PHP
如果有人有興趣幫助我,這里是所有代碼:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Etego</title>
</head>
<body>
<div align="center">
<h3>Sign Up</h3>
<br /> <br /> <br />
<form method="post" action="">
<table>
<tr>
<td align="right" > <label for="username">Username</label> </td>
<td > <input type="text" placeholder="Username" id="username" name="username" /> </td>
</tr>
<!-- ------------------------------------------------------------------------------------------------------- -->
<tr>
<td align="right" > <label for="email">Email</label> </td>
<td > <input type="email" placeholder="email" id="email" name="email" /> </td>
</tr>
<!-- ------------------------------------------------------------------------------------------------------- -->
<tr>
<td align="right" > <label for="email2">Confirm Email</label> </td>
<td > <input type="email" placeholder="re-enter email" id="email2" name="email2" /> </td>
</tr>
<!-- ------------------------------------------------------------------------------------------------------ -->
<tr>
<td align="right" > <label for="password">Password</label> </td>
<td > <input type="password" placeholder="password" id="password" name="password" /> </td>
</tr>
<!--------------------------------------------------------------------------------------------------------- -->
<tr>
<td align="right" > <label for="password2">Confirm Password</label> </td>
<td > <input type="password" placeholder="re-enter Password" id="password2" name="password2" /> </td>
</tr>
<!-- ------------------------------------------------------------------------------------------------------- -->
<tr>
<td>
<p>
<td>
What is your Gender?
<select name="formGender">
<option value="NS">non specified</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</td>
<td > <input type="hidden" placeholder="" id="gender" name="gender" /> </td>
</p>
</td>
</tr>
<!-- ------------------------------------------------------------------------------------------------------- -->
<tr>
<td></td>
<td>
<br />
<input type="submit" name="signup" value="Sign Up">
<input type="hidden" name="sign" value="true">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
$bdd = new PDO ('mysql:host=127.0.0.1;dbname=members', 'root' , '');
$gender = htmlspecialchars($_POST['gender']);
$username = htmlspecialchars($_POST['username']);
$email = htmlspecialchars($_POST['email']);
$email2 = htmlspecialchars($_POST['email2']);
$password = sha1($_POST['password']);
$password2 = sha1($_POST['password2']);
$reqemail = $bdd->prepare("SELECT * FROM members WHERE email = ?");
$reqemail->execute(array($email));
$emailexist = $reqemail->rowCount();
if($emailexist == 0) {
$passwordlenght = strlen($password);
if($passwordlenght >= 4) {
$usernamelenght = strlen($username);
if($usernamelenght <= 25) {
if($email == $email2) {
if($password == $password2) {
if (filter_var($email, FILTER_VALIDATE_EMAIL )) {
$insertmbr = $bdd->prepare("INSERT INTO members(username, email, password, gender) VALUES(?, ?, ?, ?)");
$insertmbr->execute(array($username, $email, $password, $gender));
echo "<p> <font color=red font face='arial' size='3pt'>Your account has been created</font> </p>";
header('location:login.php');
} else {
echo "<p> <font color=red font face='arial' size='3pt'>Your email isnt valid!</font> </p>";
}
} else {
echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation password doesnt match with your password</font> </p>";
}
} else {
echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation email doesnt match with your email</font> </p>";
}
} else {
echo "<p> <font color=red font face='arial' size='3pt'>Your username may not exceed 25 characters</font> </p>";
}
} else {
echo "<p> <font color=red font face='arial' size='3pt'>Your password must be 5 characters or more</font> </p>";
}
} else {
echo "<p> <font color=red font face='arial' size='3pt'>Your email is already being used by a user</font> </p>";
}
//---------------------------------------------EMPTY FIELDS ERROR-----------------------------------------------------------------------------------------
if (!empty($_POST['sign']) && $_POST['sign']=="true")
if($_POST['sign']=="true") {
if(empty($_POST['username'])) {
echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill username</font> </p>";
} else {
$username = $_POST['username'];
}
if(empty($_POST['email'])) {
echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill email</font> </p>";
} else {
$email = $_POST['email'];
}
if(empty($_POST['email2'])) {
echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill confirmation email</font> </p>";
} else {
$email2 = $_POST['email2'];
}
if(empty($_POST['password'])) {
echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill password</font> </p>";
} else {
$password = $_POST['password'];
}
if(empty($_POST['password2'])) {
echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill confirmation password</font> </p>";
} else {
$password2 = $_POST['password2'];
}
}
?>
我使用 phpmyadmin,“成員”是我的瀏覽器,它有 ID、用戶名、密碼、電子郵件,我最近添加了性別。
嗨,查爾斯,您的代碼非常非常混亂,但是我學到了一些功能,也許下次修復您的代碼。 也是為了你好。 我修復了您的代碼,但您將使用兩個 php,一個用於 signup.php,第二個是 login.php <--signup.php-->
<html>
<head>
<meta charset="utf-8">
<title>Etego</title>
</head>
<body>
<div align="center">
<h3>Sign Up</h3>
<br /><br /><br />
<form method="POST" action="login.php">
<table>
<tr>
<td align="right" > <label for="username">Username</label> </td>
<td > <input type="text" placeholder="Username" id="username" name="username" /> </td>
</tr>
<tr>
<td align="right" > <label for="email">Email</label> </td>
<td><input type="email" placeholder="email" id="email" name="email" /> </td>
</tr>
<tr>
<td align="right" > <label for="email2">Confirm Email</label> </td>
<td > <input type="email" placeholder="re-enter email" id="email2" name="email2" /> </td>
</tr>
<tr>
<td align="right" > <label for="password">Password</label> </td>
<td > <input type="password" placeholder="password" id="password" name="password" /> </td>
</tr>
<tr>
<td align="right" > <label for="password2">Confirm Password</label> </td>
<td > <input type="password" placeholder="re-enter Password" id="password2"
name="password2" /> </td>
</tr>
<tr>
<td>
<p>
<td>
What is your Gender?
<select name="gender">
<option value="NS">non specified</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</td>
<td><input type="hidden" placeholder="" id="gender" name="gender" /> </td>
</p>
</td>
</tr>
<tr>
<td></td>
<td>
<br />
<input type="submit" name="signup" value="Sign Up">
<input type="hidden" name="sign" value="true">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
//登錄.php
<?php
$bdd = new PDO ('mysql:host=localhost;dbname=dbname', 'root' , '');//make sure your
database name was really a members
$gender = htmlspecialchars($_POST["gender"]);
$username = htmlspecialchars($_POST['username']);
$email = htmlspecialchars($_POST['email']);
$email2 = htmlspecialchars($_POST['email2']);
$password = sha1($_POST['password']);
$password2 = sha1($_POST['password2']);
$reqemail = $bdd->prepare("SELECT * FROM members");
$reqemail->execute(array($email));
$emailexist = $reqemail->rowCount();
if($emailexist == 0)
{
$passwordlenght = strlen($password);
if($passwordlenght >= 4)
{
$usernamelenght = strlen($username);
if($usernamelenght <= 25)
{
if($email == $email2)
{
if($password == $password2)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL ))
{
$insertmbr = $bdd->prepare("INSERT INTO members(username, email, password, gender)
VALUES(?,?,?,?)");
$insertmbr->execute(array($username, $email, $password, $gender));
echo "<p> <font color=green font face='arial' size='3pt'>Your account has been created</font> </p>";
header('location:');
}
else
{
echo "<p> <font color=red font face='arial' size='3pt'>Your email isnt valid!
</font> </p>";
}
}
else
{
echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation
password doesnt match with your password</font> </p>";
}
}
else
{
echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation email
doesnt match with your email</font> </p>";
}
}
else
{
echo "<p> <font color=red font face='arial' size='3pt'>Your username may not
exceed 25 characters</font> </p>";
}
}
else
{
echo "<p> <font color=red font face='arial' size='3pt'>Your password must be 5
characters or more</font> </p>";
}
}
else
{
echo "<p> <font color=red font face='arial' size='3pt'>Your email is already
being used by a user</font> </p>";
}
if (!empty($_POST['sign']) && $_POST['sign']=="true")
if($_POST['sign']=="true") {
if(empty($_POST['username']))
{ echo "<p> <font color=red font face='arial' size='3pt'>please go back and
fill username</font> </p>"; }
else { $username = $_POST['username'];}
if(empty($_POST['email']))
{ echo "<p> <font color=red font face='arial' size='3pt'>please go back and
fill email</font> </p>"; }
else { $email = $_POST['email']; }
if(empty($_POST['email2']))
{ echo "<p> <font color=red font face='arial' size='3pt'>please go back and
fill confirmation email</font> </p>"; }
else { $email2 = $_POST['email2']; }
if(empty($_POST['password']))
{ echo "<p> <font color=red font face='arial' size='3pt'>please go back and
fill password</font> </p>"; }
else { $password = $_POST['password']; }
if(empty($_POST['password2']))
{ echo "<p> <font color=red font face='arial' size='3pt'>please go back and
fill confirmation password</font> </p>"; }
else { $password2 = $_POST['password2']; }
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.