Advertisement
Guest User

Apply.php

a guest
Sep 26th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?PHP
  2. # This is the MySQL Information so fill it out
  3. $user_name = "EDITTHIS";
  4. $password = "EDITTHIS";
  5. $database = "EDITTHIS";
  6. $server = "EDITTHIS";
  7.  
  8. # Connecting to the database
  9. $db_handle = mysql_connect($server, $user_name, $password);
  10. $db_found = mysql_select_db($database, $db_handle);
  11.  
  12. # If the database is found
  13. if ($db_found) {
  14.  
  15. # Selecting all the rows where the playername = The form from before
  16. $SQL = "SELECT * FROM sqlapply Where playername = ?";
  17. $result = mysql_query($SQL);
  18. if ($stmt->execute(array($_POST['user']))) {
  19.     $num_results = mysql_num_rows($result);
  20.     if($num_results > 0) {
  21. while ($db_field = mysql_fetch_assoc($result)) {
  22. # If previous apply code already found then print it
  23.     print '<font size="+4">Your Apply Password is '.$db_field['applypassword'].'</font>';
  24. }
  25.     } else {
  26.     # Getting random string
  27.         $pass = ran_string(5); # The number represents how long the string will be
  28.         #Insterting their string into the database
  29.         $stmt = $dbh->prepare("INSERT INTO sqlapply (playername, applypassword) VALUES (?, ?)");
  30.         $stmt->bindParam(1, $_POST['user']);
  31.         $stmt->bindParam(2, $pass);
  32.         $stmt->execute();
  33.        
  34.         # Telling user their random code
  35.         print '<font size="+4">Your Apply Password is '.$pass.'</font>';
  36.        
  37.     }
  38. }
  39. }
  40.  
  41. else {
  42. # If the database isnt found then print that
  43. print "Database NOT Found ";
  44. mysql_close($db_handle);
  45. }
  46.  
  47. function rand_string( $length ) {
  48. # What characters the random code can contain
  49.     $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 
  50.  
  51.     #Creating the string
  52.     $size = strlen( $chars );
  53.     for( $i = 0; $i < $length; $i++ ) {
  54.         $str .= $chars[ rand( 0, $size - 1 ) ];
  55.     }
  56.  
  57.     return $str;
  58. }
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement