Я пытаюсь создать форму регистрации, и она возвращает «Неверный адрес электронной почты», хотя формат электронной почты правильный. Я где-то читал, «как возвращать сообщения об ошибках на той же странице», и опробовал шаги, и он отлично работает для страницы входа.
signup_script. php
<?php
$con=mysqli_connect("localhost:3308", "root", "", "new") or die(mysqli_error($con));
session_start();
$name= mysqli_real_escape_string($con,$_POST['name']);
$email= mysqli_real_escape_string($con,$_POST['email']);
$pass= mysqli_real_escape_string($con,$_POST['password']);
$phone= mysqli_real_escape_string($con,$_POST['contact']);
$city= mysqli_real_escape_string($con,$_POST['city']);
$add= mysqli_real_escape_string($con,$_POST['address']);
$regex_email="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$";
if(!(preg_match($regex_email, $email))){
$_SESSION['error']="Incorrect email!";
header('location:signup.php');
}
if(strlen($pass<6)){
$_SESSION['error']="Password too short!";
header('location:signup.php');
}
$query_1="SELECT * FROM `users` WHERE email=$email";
$r=mysqli_query($con, $query_1) or die(mysqli_error($con));
if(mysqli_num_rows($r)>0){
$_SESSION['error']="Email already exists!";
header("location:signup.php");
} else{
$pass= md5($pass);
$query_2="INSERT INTO `users` (name, email, password, contact, city, address) VALUES ($name, $email, $pass, $phone, $city, $add)";
$input= mysqli_query($con, $query_2) or die(mysqli_error($con));
$_SESSION['id']= mysqli_insert_id($con);
header("location:index.php");
}
?>
регистрация. php
<?php
require 'Includes/common.php';
?>
<html>
<head>
<title>Signup | Lifestyle Store</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php
include 'Includes/header.php';
?>
<div class="container content">
<div class="row row_style">
<div class="col-xs-5 col-xs-offset-4">
<h2>Sign Up</h2>
<form method="POST" action="signup_script.php">
<div class="form-group">
<input type="text" class="form-control" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" required pattern=".{6,}">
</div>
<div class="form-group">
<input type="text" class="form-control" name="contact" placeholder="Contact" required>
</div>
<div class="form-group">
<input type="text" class="form-control" name="city" placeholder="City" required>
</div>
<div class="form-group">
<input type="text" class="form-control" name="address" placeholder="Address" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button><br><br>
<?php
if(isset($_SESSION['error'])){
$error=$_SESSION['error'];
echo "<p style='color: #fd1818'><i>$error</i></p><br>";
}
?>
<p>Already have an account? <a href="login.html">Login</a></p>
</form>
</div>
</div>
</div>
<?php
include 'Includes/footer.php';
?>
</body>
</html>
<?php
unset($_SESSION['error']);
?>