Guest User

Apply.php

a guest
Oct 14th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?PHP
  2. # If its loaded without form aka. if its in an iframe.
  3. if($_POST['user'] == "") {
  4.         print '<font size="+4">Enter Username and press submit</font>';
  5.         } else {
  6. # This is MySql information so fill it out
  7. $user_name = "die";
  8. $password = "die";
  9. $database = "die";
  10. $server = "die";
  11. # Connecting to the database
  12. $db_handle = mysql_connect($server, $user_name, $password);
  13. $db_found = mysql_select_db($database, $db_handle);
  14.  
  15. if ($db_found) {
  16.  
  17. $mysqli = new mysqli($server, $user_name, $password, $database);
  18.   if(mysqli_connect_errno()) {
  19.       echo "Connection Failed: " . mysqli_connect_errno();
  20.       exit();
  21.   }
  22.  
  23.   if($stmt = $mysqli -> prepare("SELECT * FROM sqlapply Where playername=? VALUES (?)")) {
  24.  
  25.       /* Bind parameters
  26.         s - string, b - boolean, i - int, etc */
  27.       $stmt -> bind_param("s", $_POST['user']);
  28.  
  29.       /* Execute it */
  30.       $stmt -> execute();
  31.  
  32.       /* Bind results */
  33.       $stmt -> bind_result($result);
  34.      
  35.       /* Fetch the value */
  36.       $stmt -> fetch();
  37.  
  38.       /* Close statement */
  39.       $stmt -> close();
  40.   }
  41. /*$SQL = "SELECT * FROM sqlapply Where playername =". $_POST['user'];
  42. $result = mysql_query($SQL);
  43. */
  44. if ($result) {
  45. while ($db_field = mysql_fetch_assoc($result)) {
  46.     print '<font size="+4">Your Apply Password is '.$db_field['applypassword'].'</font>';
  47.     }
  48. }else {
  49.         $pass = rand_string(5);
  50.  
  51.        
  52. $mysqli = new mysqli($server, $user_name, $password, $database);
  53.  
  54.   if(mysqli_connect_errno()) {
  55.       echo "Connection Failed: " . mysqli_connect_errno();
  56.       exit();
  57.   }
  58.  
  59.   /* Create a prepared statement */
  60.   if($stmt = $mysqli -> prepare("INSERT INTO sqlapply (playername, applypassword, time) VALUES (?, ?, ?)")) {
  61.  
  62.       /* Bind parameters
  63.         s - string, b - boolean, i - int, etc */
  64.       $stmt -> bind_param("sss", $_POST['user'], $pass, time());
  65.  
  66.       /* Execute it */
  67.       $stmt -> execute();
  68.  
  69.       /* Bind results
  70.       $stmt -> bind_result($result);
  71. */
  72.       /* Fetch the value */
  73.       $stmt -> fetch();
  74.  
  75.       /* Close statement */
  76.       $stmt -> close();
  77.   }
  78.  
  79.   /* Close connection */
  80.   $mysqli -> close();
  81.        
  82. # Printing the password
  83.        print '<font size="+4">'.$_POST['user'].' Your Apply Password is '.$pass.'</font>';
  84.         print '<p><font size="+4"> Valid for 1 hour</font></p>';
  85.         print '<p><font size="+4">Make sure name is exact capitals</font></p>';
  86.        
  87.     }
  88.  
  89. }else {
  90. print "Database NOT Found ";
  91. mysql_close($db_handle);
  92. }
  93. }
  94.  
  95. function rand_string( $length ) {
  96. # Characters random string can contain
  97.    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";  
  98.  
  99. # Creating the string
  100.    $size = strlen( $chars );
  101.     for( $i = 0; $i < $length; $i++ ) {
  102.         $str .= $chars[ rand( 0, $size - 1 ) ];
  103.     }
  104.  
  105.     return $str;
  106. }
  107.  
  108.  
  109. ?>
Advertisement
Add Comment
Please, Sign In to add comment