Advertisement
Guest User

Untitled

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