Guest User

Untitled

a guest
Jun 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. //Check for mysql connection
  4. if (!mysql_connect("host","user","pass"))
  5.   die('Could not connect: ' . mysql_error());
  6.  
  7. //Escape SQL characters to protect against SQL injection
  8. $username = mysql_real_escape_string($_POST['username']);
  9. $hostname = mysql_real_escape_string($_POST['hostname']);
  10. $ip = mysql_real_escape_string($_POST['ip']);
  11. $email = mysql_real_escape_string($_POST['email']);
  12.  
  13. mysql_select_db("database");
  14.  
  15. //Query to check for username match
  16. $userCheck = "SELECT * FROM `Accounts` WHERE username = '$username'";
  17.  
  18. if(mysql_num_rows(mysql_query($userCheck)) != 0)
  19.     die("Sorry, username is already in use. Please go back and try again.");
  20.  
  21. //If the username isn't found, insert the values
  22. $sql = "INSERT INTO Accounts VALUES ('$username','$hostname','$ip','$email')";
  23.  
  24. if (mysql_query($sql)) {
  25.     //Successful query
  26.     header ("location: /done.html");
  27.     exit();
  28. } else
  29.     //Failed query
  30.     die("Something is wrong, we could not complete your request.");
  31. ?>
Add Comment
Please, Sign In to add comment