Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. <?php session_start() ?>
  2. <html>
  3.     <head><title>User Dashboard</title></head>
  4.     <body><center><h3>Welcome to your Dashboard!</h3></center>
  5.             <form name="Form2" method="post" action="dashboard.php">
  6.                 Add Table: <input type="text" name="addTable"/>
  7.                 Remove Table: <input type="text" name="removeTable" />
  8.                 <input type="submit" name="Submit" />
  9.             </form>
  10.         </body>
  11. </html>
  12.  
  13. <?php
  14.     $dsn = "mysql:dbname={$_SESSION['dbname']}" ; "host=localhost";
  15.     $user = "{$_SESSION['username']}";
  16.     $password = "{$_SESSION['password']}";
  17.    
  18.     try {
  19.             $dbh = new PDO($dsn, $user, $password);
  20.         } catch (PDOException $e) {
  21.             echo 'Connection failed : ' , $e->getMessage();
  22.         }
  23.  
  24.     if (isset($_POST['addTable']))
  25.     {
  26.         $addTable = $_POST['addTable'];
  27.         $SQLaddTable = "CREATE TABLE $addTable(
  28.                        id INT NOT NULL AUTO_INCREMENT,
  29.                        PRIMARY KEY(id),
  30.                        name VARCHAR(30),
  31.                        age INT)";
  32.         try {
  33.             $dbh->query($SQLaddTable);
  34.             echo "The $addTable table was successfully created.";
  35.         }catch (Exception $e) {
  36.             echo "$addTable could not be added." , $e->getMessage(),"\n";
  37.             }
  38.     }
  39.  
  40.     else if (isset($_POST['removeTable']))
  41.     {  
  42.         $removeTable = $_POST['removeTable'];
  43.         $SQLremoveTable = "DROP TABLE $removeTable";
  44.         try {
  45.             $dbh->query($SQLremoveTable);
  46.             echo "The $removeTable table was successfully removed.";
  47.         }catch (Exception $e) {
  48.             echo "$removeTable could not removed." , $e->getMessage() , "\n";
  49.             }
  50.     }
  51.     $dbh = null;
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement