Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- # This is the MySQL Information so fill it out
- $user_name = "EDITTHIS";
- $password = "EDITTHIS";
- $database = "EDITTHIS";
- $server = "EDITTHIS";
- # Connecting to the database
- $db_handle = mysql_connect($server, $user_name, $password);
- $db_found = mysql_select_db($database, $db_handle);
- # If the database is found
- if ($db_found) {
- # Selecting all the rows where the playername = The form from before
- $SQL = "SELECT * FROM sqlapply Where playername = ?";
- $result = mysql_query($SQL);
- if ($stmt->execute(array($_POST['user']))) {
- $num_results = mysql_num_rows($result);
- if($num_results > 0) {
- while ($db_field = mysql_fetch_assoc($result)) {
- # If previous apply code already found then print it
- print '<font size="+4">Your Apply Password is '.$db_field['applypassword'].'</font>';
- }
- } else {
- # Getting random string
- $pass = ran_string(5); # The number represents how long the string will be
- #Insterting their string into the database
- $stmt = $dbh->prepare("INSERT INTO sqlapply (playername, applypassword) VALUES (?, ?)");
- $stmt->bindParam(1, $_POST['user']);
- $stmt->bindParam(2, $pass);
- $stmt->execute();
- # Telling user their random code
- print '<font size="+4">Your Apply Password is '.$pass.'</font>';
- }
- }
- }
- else {
- # If the database isnt found then print that
- print "Database NOT Found ";
- mysql_close($db_handle);
- }
- function rand_string( $length ) {
- # What characters the random code can contain
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- #Creating the string
- $size = strlen( $chars );
- for( $i = 0; $i < $length; $i++ ) {
- $str .= $chars[ rand( 0, $size - 1 ) ];
- }
- return $str;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement