Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- echo $_POST['table'];
- ?>
- </title>
- </head>
- <body>
- <?php
- $table = $_POST['table'];
- $passcode = $_POST['passcode'];
- if (hash('sha256', 'salty' . $passcode) != "548a6455bd6655e3def805c36baddfcdab2ba1b0846fd57daa127b55ff54ff58") {
- echo "Wrong passcode!";
- } else {
- $dsn = "";
- $user = "";
- $password = "";
- // setup link to DB
- $link = new PDO($dsn,$user,$password);
- ?>
- <table border="1">
- <?php
- // get headers
- $stmt = $link -> prepare ("SELECT column_name FROM information_schema.columns WHERE table_name='${table}'");
- $stmt -> execute();
- $headers = array();
- $data = "<tr>\n";
- $k = 0;
- while ($header = $stmt -> fetch()) {
- $data .= "<th>" . $header[0] . "</th>\n";
- $headers[$k] = $header[0];
- ++$k;
- }
- echo $data . "</tr>\n";
- // get data
- $stmt = $link -> prepare ("SELECT * FROM ${table};");
- $stmt -> execute();
- $cols = $stmt -> columnCount();
- $j = 1;
- echo "<form=\"data\" action=\"edit_db.php\" method=\"post\">\n";
- while ($row = $stmt-> fetch()) {
- $table_row = "<tr>\n";
- for ($i = 0; $i < $cols; ++$i) {
- $table_row .= "<td><input type=\"text\" name=\"" . $headers[$i] . "[$j]" . "\" value=\"" . $row[$i] . "\" /></td>\n";
- }
- $table_row .= "</tr>\n";
- echo $table_row;
- }
- // "add row" line
- $new_row = "<tr>\n";
- for ($i = 0; $i < $cols; ++$i) {
- $new_row .= "<td><input type=\"text\" name=\"" . $headers[$i] . "[new]\" value=\"\" /></td>\n";
- }
- $new_row .= "</tr>\n";
- echo $new_row;
- ?>
- </table>
- <br><input type="submit" value="Submit" />
- <?php
- // close database
- $stmt -> closeCursor();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement