我正在制作一个帐户表单,在一个网站的单个页面上都有登录和注册表单,注册表单与数据库一起工作很好,但我无法登录。
下面是uaccount.php (my forms)的代码
<form action="uregistration.php" method="post">
<!--SIGN UP FORM HERE-->
<h1>Create Account</h1>
<input type="text" id="firstname" name="firstname" placeholder="First Name" required>
<input type="text" id="lastname" name="lastname" placeholder="Last Name" required>
<input type="email" id="email" name ="email" placeholder="Email" required>
<input type="password" id="password" name="password" placeholder="Password" required>
<input type="date" id="birthdate" name="birthdate" placeholder="Birthdate" required>
<input type="text" id="contact" name="contact" placeholder="Contact No." maxlength = "11" required>
<select type= "text" id="gender" name="gender" placeholder="Gender" required>
<option selected disabled> Select your gender </option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="others">Others</option>
</select>
<button type="submit" id="register" name= "register">Sign Up</button>
</form>
</div>
<a href="index.php"> <i class="fa fa-times-circle-o"></i> </a>
<form action= "uvalidation.php" method="post">
<!--SIGN IN FORM HERE-->
<h1> Sign in </h1>
<input type="email" id="email" name ="email" placeholder="Email" required>
<input type="password" id="password" name="password" placeholder="Password" required>
<a href ="#">Forgot your Password?</a>
<button type="submit" id="login" name= "login">Sign In</button>
</form>
</div>
</body>
</html>
下面是uregistration.php(注册表单数据库连接)的代码
<?php
session_start();
header('Location: uaccount.php');
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'castro_rentals');
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = sha1($_POST['password']);
$birthdate = $_POST['birthdate'];
$contact = $_POST['contact'];
$gender = $_POST['gender'];
$s = " SELECT * FROM user WHERE email = '$email'";
$result = mysqli_query($con, $s);
$num = mysqli_num_rows($result);
if ($num == 1) {
echo "Email already taken!";
}else{
$reg = " insert into user
(firstname, lastname, email, password, birthdate,
contact, gender)
VALUES ('$firstname' , '$lastname' , '$email' ,
'$password' , '$birthdate' , '$contact' ,
'$gender')";
mysqli_query($con, $reg);
echo " Registration Successful!";
}
下面是uvalidate .php(登录表单数据库连接)的代码
<?php
session_start();
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'castro_rentals');
$email = $_POST['email'];
$password = sha1($_POST['password']);
$s = " SELECT * FROM user WHERE email = '$email' AND password = '$password'";
$result = mysqli_query($con, $s);
$num = mysqli_num_rows($result);
if ($num == 1) {
header('Location: index.php');
}else{
header('Location: uaccount.php');
}
最后,这里是index.php的代码(我想在验证登录后重定向我的页面)
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title> Home | Castro Rentals </title>
</head>
<body>
Welcome!!
</body>
</html>
我试过了
- 位置中大写字母L
- 删除标题内的空白位置:
- 也删除了关闭?>php结束标签
我修好了!我删除了uvalidation.php上的sha(1) !我忘记删除了因为我从uregistration。php
复制粘贴了它我在(uvalidation.php)之前的代码:$email = $_POST['email']; $password = sha1($_POST['password']);
我的代码后(uvalidation.php):$email = $_POST['email']; $password = ($_POST['password']);