Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php session_start() ?>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4.     <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.         <title>Login page</title>
  7.     </head>
  8.     <body>
  9.         <center><h3>Enter your credentials</h3></center>
  10.  
  11.         <form name="Form1" method="post" action="index.php">
  12.  
  13.         Username: <input type="text" name="username" />
  14.         Password: <input type="text" name="password" />
  15.         DB Name: <input type="text" name="dbname" />
  16.         <input type="submit" name="submit" />
  17.         </form>
  18.        
  19.         <?php
  20.             if (!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['dbname']))
  21.             {
  22.                 $_SESSION['dbname'] = $_POST['dbname'];
  23.                 $_SESSION['username'] = $_POST['username'];
  24.                 $_SESSION['password'] = $_POST['password'];
  25.              
  26.                 $dsn = 'mysql:host=localhost';
  27.                 $user = 'root';
  28.                 $password = 'ONGOINGwarfare1+2+3+';
  29.                 try {
  30.                     $dbh = new PDO($dsn, $user, $password);
  31.                 } catch (PDOException $e) {
  32.                     echo 'Connection failed : ' , $e->getMessage();
  33.                 }
  34.  
  35.                 $SQL1 = "CREATE DATABASE {$_SESSION['dbname']}";
  36.                 $dbh->query($SQL1);
  37.                 $SQL2 = "CREATE USER {$_SESSION['username']} IDENTIFIED by '{$_SESSION['password']}'";
  38.                 $dbh->query($SQL2);
  39.                 $SQL3 = "GRANT all privileges ON {$_SESSION['dbname']}.* to '{$_SESSION['username']}'@'localhost' IDENTIFIED by '{$_SESSION['password']}'";
  40.                 $dbh->query($SQL3);
  41.                
  42.                 echo "{$_SESSION['dbname']} was successfully created, now you can log into your database on Hive696 using the following line: <br>
  43.                        \"mysql -u{$_SESSION['username']} -p{$_SESSION['password']}\"";
  44.                 $dbh = null;
  45.             }
  46.             elseif (empty($_POST['username'])) //----------HERE-----------
  47.             {
  48.                 echo 'Error';
  49.             }
  50.         ?>
  51.     </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement