Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- if (count($_POST)>0)
- {
- $incoming = $_POST;
- $fields_with_content = 0;
- $empty_fields = 0;
- $sql = 'INSERT INTO entries SET ';
- $sep = '';
- foreach($incoming as $key=>$value)
- {
- echo "The input field <b>$key</b> contains the value '$value'<br>\n";
- if (strlen(trim($value))>0)
- {
- $fields_with_content++;
- $value = trim(str_replace("\r", "", $value)); // remove Windows specific CR characters
- $sql .= $sep.'`'.preg_replace('%[^a-zA-Z0-9_ ]%', '', $key)."`='".mysql_real_escape_string($value)."'";
- $sep = ', ';
- } else
- {
- $empty_fields++;
- }
- }
- echo "<br><hr><br>\nFields with contents: $fields_with_content<br>\n";
- echo "Empty fields: $empty_fields<br>\n";
- echo htmlspecialchars($sql)."<br>\n";
- exit;
- }
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>scrchpst input shizzles</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <style type="text/css">
- body { max-width: 450px; font-family: constantia, cambria, times; font-size: 12px; background: #E0E0E0; color: #000000; margin: 50px; }
- h1 { font-family: calibri, tahoma, verdana; color: #003080; font-size: 25px; margin: 17px 0px 9px 0px; border: #B0B0B0 solid; border-width: 0px 0px 1px 0px; }
- h2 { font-family: calibri, tahoma, verdana; color: #003080; font-size: 19px; margin: 15px 0px 5px 0px; }
- h3 { font-family: calibri, tahoma, verdana; color: #003080; font-size: 15px; margin: 13px 0px 5px 0px; }
- textarea { width: 313px; height: 150px; }
- </style>
- </head>
- <body>
- <form action="arrayinput.php" method="post">
- <h1>Type in stuff</h1>
- <input type="text" name="first_name" placeholder="First name">
- <input type="text" name="last_name" placeholder="Last name"><br>
- <textarea name="description"></textarea><br>
- <input type="submit" value="OK">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment