Skip to content

Instantly share code, notes, and snippets.

@anthonycvella
Created February 1, 2013 03:17
Show Gist options
  • Save anthonycvella/4688889 to your computer and use it in GitHub Desktop.
Save anthonycvella/4688889 to your computer and use it in GitHub Desktop.
function register()
{
global $db;
if (isset($_POST['username']) && isset($_POST['passwordMD5']) && isset($_POST['email']))
{
$username = mysql_real_escape_string($_POST['username']);
$passwordMD5 = mysql_real_escape_string($_POST['passwordMD5']);
$email = mysql_real_escape_string($_POST['email']);
$db->query("SELECT username, email FROM users WHERE username=? OR email=?")->bind(1, $username)->bind(2, $email)->execute();
if ($db->getTotalRows()) {
$result = $db->fetch();
$resultusername = $result['username'];
$resultemail = $result['email'];
}
if ($username != $resultusername || $email != $resultemail) {
$db->query("INSERT INTO users (username', 'password', 'email') VALUES (?, ?, ?)")->bind(1, $username)->bind(2, $passwordMD5)->bind(3, $email)->execute();
header('Content-type: application/json');
echo json_encode(array(
'username' => $username,
'email' => $email,
'status' => 'Registration Passed'
));
return true;
} else {
header('Content-type: application/json');
echo json_encode(array(
'username' => $username,
'email' => $email,
'status' => 'Registration Failed'
));
return false;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment