Skip to content

Instantly share code, notes, and snippets.

@cFerg cFerg/index.php Secret
Last active Aug 29, 2015

Embed
What would you like to do?
<?php
$userErr = "";
$mailErr = "";
$passErr = "";
$regErr = "";
//submittion for registering
if (!empty($_POST['register-submit'])){
//connection
require('db/conn.php');
dbconn($db_host, $db_name, $db_user, $db_pass);
// define variables and set to empty values
$userSet = 0;
$mailSet = 0;
$passSet = 0;
//retrive data from POST form
$ruser = $_POST['RegUser'];
$rmail = $_POST['RegMail'];
$rpass = $_POST['RegPass'];
if (empty($_POST["RegUser"])) {
$userErr = "(Name is required)";
}elseif (!preg_match("#[a-zA-Z0-9_]+#", $ruser)){
$userErr = "(Please Only Use Letters, Numbers, and Underscores.)";
}else {
$sql1 = "SELECT * FROM `Members` WHERE `username` = '" . mysql_real_escape_string($ruser) . "'";
$result1 = mysql_query($sql1) or ($regErr = "Error looking up username.");
$row1 = mysql_fetch_assoc($result1);
if(mysql_num_rows($result1)) {
$userErr = "(This Username is already registered.)";
}else{
$userErr = "";
$userSet = 1;
}
}
if (empty($_POST["RegMail"])) {
$mailErr = "(Email is required)";
}else{
//check if email already exists
$sql2 = "SELECT * FROM `Members` WHERE `email` = '" . mysql_real_escape_string($rmail) . "'";
$result2 = mysql_query($sql2) or ($regErr = "Error looking up email.");
$row2 = mysql_fetch_assoc($result2);
if(mysql_num_rows($result2)) {
$mailErr = "(This Email is already registered.)";
}else{
$mailErr = "";
$mailSet = 1;
}
}
if (empty($_POST["RegPass"])) {
$passErr = "(Password is required)";
}elseif (strlen($rpass) <= 5){
$passErr = "(Password needs to be 'at least' 6 characters)";
}else {
$passErr = "";
$passSet = 1;
}
if (($userSet == 1) && ($mailSet == 1) && ($passSet == 1)){
$ruser2 = mysql_real_escape_string($_POST['RegUser']);
$rpass2 = mysql_real_escape_string($_POST['RegPass']);
$repass = password_hash($rpass, PASSWORD_DEFAULT);
$rmail2 = mysql_real_escape_string($_POST['RegMail']);
//insert data into DB
$query = "INSERT INTO `Members` (`username`, `password`, `email`) VALUES ('$ruser2', '$repass', '$rmail2')";
mysql_query($query) or ($regErr = "Error creating the account.");
$userErr = "";
$passErr = "";
$mailErr = "";
$conn->close();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.