Social-Network/register.php

82 lines
2.4 KiB
PHP

<?php
$con = mysqli_connect("192.168.1.2:3306", "social_dev", "Ellie-521890@", "social");
if(mysqli_connect_errno()) {
echo "Failed to connect to database: " . mysqli_connect_errno();
}
// Variables declaration to prevent errors
$fname = "";
$lname = "";
$email = "";
$email_conf = "";
$pass = "";
$pass_conf = "";
$date = ""; // Registration Date
$errors = ""; // Used to hold any errors.
if(isset($_POST['register_but'])) {
// Variable Assignments
// *** strip_tags() is used to prevent html injection. *** //
$fname = strip_tags($_POST['reg_fname']); //Sets the value from the forum.
$fname = str_replace(' ', '', $fname); // Removes any spaces.
$fname = ucfirst(strtolower($fname)); // Capitalizes first letter, lowercases the rest.
$lname = strip_tags($_POST['reg_lname']);
$lname = str_replace(' ', '', $lname);
$lname = ucfirst(strtolower($lname));
$email = strip_tags($_POST['reg_email']);
$email = str_replace(' ', '', $email);
$email = strtolower($email);
$email_conf = strip_tags($_POST['reg_email_conf']);
$email_conf = str_replace(' ', '', $email_conf);
$email_conf = strtolower($email_conf);
$pass = strip_tags($_POST['reg_pass']);
$pass = str_replace(' ', '', $pass);
$pass_conf = strip_tags($_POST['reg_pass_conf']);
$pass_conf = str_replace(' ', '', $pass_conf);
$date = date(Y-m-d); // Sets the registration date.
if ($email == $email_conf) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
} else {
echo "invalid format";
}
} else {
echo "The email's do not match.";
}
}
?>
<html>
<head>
<title>Meme Machine</title>
</head>
<body>
<form action="register.php" method="POST">
<input type="text" name="reg_fname" placeholder="First Name" required>
<br>
<input type="text" name="reg_lname" placeholder="Last Name" required>
<br>
<input type="email" name="reg_email" placeholder="Email" required>
<br>
<input type="email" name="reg_email_conf" placeholder="Confirm Email" required>
<br>
<input type="password" name="reg_pass" placeholder="Password" required>
<br>
<input type="password" name="reg_pass_conf" placeholder="Confirm Password" required>
<br>
<input type="submit" name="register_but" value="Register">
</form>
</body>
</html>