Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Friends
- */
- get_header();
- function TestInput($data) {
- $badchars = array("$",",",";","/","\\","\:");
- // prevent !isset() error
- if (!isset($data)) {
- $data = ' ';
- }
- $data=trim($data);
- $data=stripslashes($data);
- $data=htmlspecialchars($data);
- $d=$data;
- $d=str_replace($badchars,"",$d);
- $d=str_replace("'","''",$d);
- if (!is_numeric($data)) { $data = $d; }
- return $data;
- }
- echo "<br /><br />T1...<br />";
- $method = strtoupper($_SERVER["REQUEST_METHOD"]);
- echo "<br /><br />T2...".$method."<br />";
- if ($method === "POST") {
- echo "<br /><br />T3...inside POST<br /><br />";
- $name = TestInput($_POST["inputName"]);
- $email = TestInput($_POST["eMail"]);
- $phone = TestInput($_POST["Phone"]);
- $zip = TestInput($_POST["Zip"]);
- $comment = TestInput($_POST["Comment"]);
- $sql = "insert into friends (fName,eMail,Zip,Phone,fSource,Comments) ";
- $sql .= "values('" . $name . "','";
- $sql .= $email . "','";
- $sql .= $zip . "','";
- $sql .= $phone . "',";
- $sql .= "'F','";
- $sql .= $comment . "')";
- $servername = "localhost";
- $username = "usrid";
- $password = "pwd";
- $dbname = "dbname";
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Database connection failed: " . $conn->connect_error);
- }
- else {
- if ($conn->query($sql) === TRUE) {
- echo "<br /><br /><p>Thank you, " . $name . ". Your information and comments have been added to the database.</p><br />";
- } else {
- echo "Error: " .$sql . "<br />" . $conn->error;
- }
- }
- } else {
- ?>
- <form method="post">
- <div>
- <div style="padding-left:50px;clear:both;width:350px;">
- <label for="inputName" style="height:50px;vertical-align:-15px;">Name:</label>
- <div style="float:right;">
- <input type="text" class="form-control" name="inputName" id="inputName" placeholder="Your Name">
- </div>
- </div>
- <div style="padding-left:50px;clear:both;width:350px;">
- <label for="eMail" style="height:50px;vertical-align:-15px;">E-Mail Address:</label>
- <div style="float:right;">
- <input type="text" class="form-control" name="eMail" id="eMail" placeholder="Your E-Mail">
- </div>
- </div>
- <div style="padding-left:50px;clear:both;width:350px;">
- <label for="Phone" style="height:50px;vertical-align:-15px;">Phone Number:</label>
- <div style="float:right;">
- <input type="text" class="form-control" name="Phone" id="Phone" placeholder="Your Phone Number">
- </div>
- </div>
- <div style="padding-left:50px;clear:both;width:350px;">
- <label for="Zip" style="height:50px;vertical-align:-15px;">Zip Code:</label>
- <div style="float:right;">
- <input type="text" class="form-control" name="Zip" id="Zip" placeholder="Your Zip Code">
- </div>
- </div>
- <div style="padding-left:50px;clear:both;width:350px;">
- <label for="Comment" style="height:50px;vertical-align:-15px;">Comments:</label>
- <div style="float:right;">
- <input type="text" class="form-control" name="Comment" id="Comment" placeholder="Comments">
- </div>
- </div>
- <div style="padding-left:50px;clear:both;width:285px;">
- <div style="height:50px;text-align:right;">
- <button type="submit">Submit</button>
- </div>
- </div>
- <br /><br />
- </div>
- </form>
- <?php }
- get_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement