Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>
  4. <?php
  5.  
  6. error_reporting(E_ALL);
  7. ini_set('display_errors', '1');
  8.  
  9. echo $_POST['table'];
  10.  
  11. ?>
  12.  
  13. </title>
  14. </head>
  15. <body>
  16.  
  17. <?php
  18.  
  19. $table = $_POST['table'];
  20. $passcode = $_POST['passcode'];
  21.  
  22. if (hash('sha256', 'salty' . $passcode) != "548a6455bd6655e3def805c36baddfcdab2ba1b0846fd57daa127b55ff54ff58") {
  23.     echo "Wrong passcode!";
  24. } else {
  25.     $dsn = "";
  26.     $user = "";
  27.     $password = "";
  28.  
  29.     // setup link to DB
  30.     $link = new PDO($dsn,$user,$password);
  31.  
  32. ?>
  33.    
  34. <table border="1">
  35.  
  36. <?php
  37.    
  38.     // get headers
  39.     $stmt = $link -> prepare ("SELECT column_name FROM information_schema.columns WHERE table_name='${table}'");
  40.     $stmt -> execute();
  41.     $headers = array();
  42.     $data = "<tr>\n";
  43.     $k = 0;
  44.     while ($header = $stmt -> fetch()) {
  45.         $data .= "<th>" . $header[0] . "</th>\n";
  46.         $headers[$k] = $header[0];
  47.         ++$k;
  48.     }
  49.     echo $data . "</tr>\n";
  50.    
  51.    
  52.     // get data
  53.     $stmt = $link -> prepare ("SELECT * FROM ${table};");
  54.     $stmt -> execute();
  55.     $cols = $stmt -> columnCount();
  56.    
  57.     $j = 1;
  58.     echo "<form=\"data\" action=\"edit_db.php\" method=\"post\">\n";
  59.     while ($row = $stmt-> fetch()) {
  60.         $table_row = "<tr>\n";
  61.         for ($i = 0; $i < $cols; ++$i) {
  62.             $table_row .= "<td><input type=\"text\" name=\"" . $headers[$i] . "[$j]" . "\" value=\"" . $row[$i] . "\" /></td>\n";
  63.         }
  64.         $table_row .= "</tr>\n";
  65.         echo $table_row;
  66.     }
  67.    
  68.     // "add row" line
  69.     $new_row = "<tr>\n";
  70.     for ($i = 0; $i < $cols; ++$i) {
  71.         $new_row .= "<td><input type=\"text\" name=\"" . $headers[$i] . "[new]\" value=\"\" /></td>\n";
  72.     }
  73.     $new_row .= "</tr>\n";
  74.     echo $new_row;
  75.    
  76. ?>
  77.  
  78. </table>
  79. <br><input type="submit" value="Submit" />
  80.  
  81. <?php
  82.    
  83.     // close database
  84.     $stmt -> closeCursor();
  85. }
  86.  
  87. ?>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement