Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Check for mysql connection
- if (!mysql_connect("host","user","pass"))
- die('Could not connect: ' . mysql_error());
- //Escape SQL characters to protect against SQL injection
- $username = mysql_real_escape_string($_POST['username']);
- $hostname = mysql_real_escape_string($_POST['hostname']);
- $ip = mysql_real_escape_string($_POST['ip']);
- $email = mysql_real_escape_string($_POST['email']);
- mysql_select_db("database");
- //Query to check for username match
- $userCheck = "SELECT * FROM `Accounts` WHERE username = '$username'";
- if(mysql_num_rows(mysql_query($userCheck)) != 0)
- die("Sorry, username is already in use. Please go back and try again.");
- //If the username isn't found, insert the values
- $sql = "INSERT INTO Accounts VALUES ('$username','$hostname','$ip','$email')";
- if (mysql_query($sql)) {
- //Successful query
- header ("location: /done.html");
- exit();
- } else
- //Failed query
- die("Something is wrong, we could not complete your request.");
- ?>
Add Comment
Please, Sign In to add comment