Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // this page checks if a username is taken , checks if a email is vailid then sends a confirmation email into it
- $email = $_POST['email'];
- $username = $_POST['username'];
- $password2 = $_POST['password'];
- $password = sha1($password2);
- $confirm_password = $_POST['confirm_password'];
- $error_email = "";
- $error_username = "";
- $error_username2 = "";
- $error_password = "";
- if($password2 !== $confirm_password){
- $error_password = "Passwords didn't match";
- }
- if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)){
- $error_email = "invalid email , please try again";
- } else {
- $to = $email;
- $subject = "Thank you for registering on my website!";
- // please add your website name in the line below
- $message = "You recently registered on my website which is called: ";
- mail($to , $subject , $message);
- }
- //you may have to edit some of this , but thats on you, email me at jdbchamp@comcast.net if you need help
- $host = "localhost";
- $username = "root";
- $password = "";
- $my_db = "test";
- $sql = mysqli($host ,$username ,$password ,$my_db);
- $username = $sql->real_escape_string($username);
- $password = $sql->real_escape_string($password);
- $email = $sql->real_escape_string($email);
- $query = "SELECT * FROM test_table WHERE username='$username'";
- $result = $sql->query($query) or die($query.'<br />'.$sql->error);
- if ($result->num_rows > 0) {
- // already exists
- } else {
- //doesnt exist
- }
- $query = "INSERT INTO test_table (email , username , password) VALUES ('$email', '$username', '$password')";
- $result = $sql->query($query) or die($query.'<br />'.$sql->error);
- if($error_email && $error_username && $error_username2 && $error_password !== ""){
- header("Location: error.php");
- echo "There was an error or maybe more please go back and fix them" . "<br />";
- echo $error_email . "<br />";
- echo $error_username . "<br />";
- echo $error_username2 . "<br />";
- echo $error_password . "<br />";
- } else {
- header("Location: success.php");
- }
Add Comment
Please, Sign In to add comment