Hi guys,
I am trying to create registration form and record the registration to the database, however, I have problem with the part for the ‘member name’ validation.
I try to register myself properly and there shouldn’t be an error however it say “Member name must contain only letters, space and hypen”.
It shouldn’t as i put the member name properly, maybe I did something wrong with the validation and especially the regex?
My apology for my bad English.
[php]<?php
session_start();
require_once(‘sqlconnect.inc.php’);
if (isset($_POST["Register"]))
{
$email = $_POST['email'];
$memberName = $_POST['membername'];
$passw = $_POST['password'];
$conPassw = $_POST['conpassword'];
if($email=='')
{
echo "<p>Please enter the Email address</p>";
echo "<a href=\"signup.php\">Back to Registration Page!</a>";
exit();
}
if($memberName=='')
{
echo "<p>Please enter the Member Name</p>";
echo "<a href=\"signup.php\">Back to Registration Page!</a>";
exit();
}
if($passw=='')
{
echo "<p>Please enter Password</p>";
echo "<a href=\"signup.php\">Back to Registration Page!</a>";
exit();
}
if($conPassw=='')
{
echo "<p>Please enter Confirm Password</p>";
echo "<a href=\"signup.php\">Back to Registration Page!</a>";
exit();
}
else {
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo "Invalid email address";
}
else{
$_SESSION['name'] = $_POST['membername'];
$pattern1 = '/^[a-z-]+$/';
if (preg_match($pattern1, $memberName))
{
echo "<p>Member name must contain only letters, space and hypen</p>";
}
else{
$pattern2 = '^[a-zA-Z0-9]+$';
if (preg_match($pattern2, $passw))
{
echo "<p>Password must only contain numbers and letters!</p>";
}
else{
if($passw<>$conPassw)
{
echo "<p>Passwords does not match!</p>";
$passw="";
$conPassw="";
}
else{
$conn = @mysqli_connect($host, $user, $pswd, $dbnm);
if (!$conn)
die ("<p>Couldn't connect to the server!<p>");
$SelectDatabase = @mysqli_select_db($conn,"s7259476_db")
or die("<p>The database is not available.</p>");
$insertDatabase = "INSERT INTO team VALUES('NULL','$email','$password','$memberName',CURDATE(),0)";
$queryResult = @mysqli_query($conn, $insertDatabase)
or die ("<p>Email already exists.Please enter another email id</p>");
echo"<p>Data entered into friends table successfully</p>";
echo "<p>Welcome"." ".$_SESSION['name']."</p>";
}
}
}
}
}
}
?>
Register PageMy Team System Registration Page
<?php $email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_SANITIZE_STRING) : ''; ?> <?php $memberName = isset($_POST['membername']) ? filter_var($_POST['membername'], FILTER_SANITIZE_STRING) : ''; ?>
Email:
Member Name:
Password:
Confirm Password:
Home
[/php]