Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
- $('#test').click(function() {
- $.ajax({
- type: "POST",
- url: "some.php",
- data: { name: "John" }
- }).done(function( msg ) {
- alert( "Data Saved: " + msg );
- });
- });
- </script>
- <style>
- body, html {
- height: 100%;
- background-color: azure;
- font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
- }
- #first{
- background-color: bisque;
- border: 5;
- padding: 7px;
- }
- #second{
- background-color: cornsilk;
- padding: 7px;
- }
- td{
- padding: 8px;
- }
- tr:hover {
- background-color:deepskyblue;
- }
- #test {
- /*
- Formatting taken from
- https://www.jotform.com/help/118-How-to-Customize-the-Submit-Button-with-CSS
- */
- background: #422bd8;
- color: white;
- border-style: outset;
- border-color: #422bd8;
- height: 30px;
- width: 100px;
- font: bold 15px arial, sans-serif;
- text-shadow:none;
- }
- </style>
- <meta charset="utf-8">
- <title>Akash insertion</title>
- </head>
- <body>
- <div id="second">
- <h1 id="Intro"> Hello </h1>
- <h3>This is a survey meant to gauge your experience with the Surface Pro 4</h3>
- <form action="sql insert php.php" method="post">
- <fieldset>
- <table>
- <tr>
- <td><label for="fName">First Name: </label></td>
- <td><input name="fname" type="text" id="fName"></td>
- </tr>
- <tr>
- <td><label for="lName">Last Name: </label></td>
- <td><input name="lname" type="text" id="lName"></td>
- </tr>
- <tr>
- <td><label for="email">Email: </label></td>
- <td><input name="loginName" type="email" id="email"></td>
- </tr>
- <tr>
- <td><label for="gradYear">Grad Year:</label></td>
- <td> <input type="radio" name="grad" value="2019"> 2019<br> </td>
- <td> <input type="radio" name="grad" value="2020"> 2020<br> </td>
- <td> <input type="radio" name="grad" value="2021"> 2021<br> </td>
- <td> <input type="radio" name="grad" value="2022"> 2022<br> </td>
- </tr>
- </table>
- </fieldset>
- <fieldset>
- <table>
- <tr>
- <td><label for="talt">Which one of these alternatives would you prefer</label></td>
- <td> <input type="radio" name="alt" value="mac"> Macbook Pro<br> </td>
- <td> <input type="radio" name="alt" value="ipad"> Ipad Pro<br> </td>
- <td> <input type="radio" name="alt" value="slaptop"> Surface Laptop<br> </td>
- <td> <input type="radio" name="alt" value="xps"> Dell XPS<br> </td>
- </tr>
- <tr>
- <td><label for="paroblems">Have you had any problems with your Surface so far:</label></td>
- <td> <input type="radio" name="problems" value="yes"> Yes<br> </td>
- <td> <input type="radio" name="problems" value="no"> No<br> </td>
- </tr>
- <br>
- </table>
- <input type="submit" name="action" value="GO">
- </fieldset>
- <!-- I would add more if I had time -->
- </form>
- </div>
- <div>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- </div>
- <?php
- if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['action']))
- {
- foreach ($_POST as $key => $value) {
- echo "<tr>";
- echo "<td>";
- echo $key;
- echo "</td>";
- echo "<br>";
- echo "<td>";
- echo $value;
- echo "</td>";
- echo "</tr>";
- echo "<br>";
- echo "<br>";
- }
- insert();
- }
- function abc(){
- echo "The function is called.";
- }
- function insert($name){
- $servername = "localhost";
- $username = "playground18";
- $password = "Cdz5SOVrY2p8fnWS";
- $dbname = "playground18";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- echo( "<h3>Connected to $dbname</h3>");
- $name = trim($_REQUEST['fname']);
- echo( "<h3>Inserting (after escaping): $name</h3>" );
- if( strlen($name) > 100 || strlen($name)< 1 ) {
- echo( '<h1>Invalid name!</h1>');
- exit();
- }
- // Update name to escape special symbols that could allow SQL injection attack
- $name = $conn->real_escape_string($name);
- ?>
- <h3>Inserting the name: "<?=$name?>"</h3>
- <?php
- $lname = trim($_REQUEST['lname']);
- echo( "<h3>Inserting (after escaping): $lname</h3>" );
- if( strlen($lname) > 100 || strlen($lname)< 1 ) {
- echo( '<h1>Invalid name!</h1>');
- exit();
- }
- // Update name to escape special symbols that could allow SQL injection attack
- $lname = $conn->real_escape_string($lname);
- ?>
- <h3>Inserting the lname: "<?=$lname?>"</h3>
- <?php
- echo
- $email = trim($_REQUEST['loginName']);
- echo( "<h3>Inserting (after escaping): $email</h3>" );
- // Update name to escape special symbols that could allow SQL injection attack
- $email = $conn->real_escape_string($email);
- ?>
- <h3>Inserting the email: "<?=$email?>"</h3>
- <?php
- $grad = trim($_REQUEST['grad']);
- echo( "<h3>Inserting (after escaping): $grad</h3>" );
- if( strlen($grad) > 100 || strlen($grad)< 1 ) {
- echo( '<h1>Invalid $grad!</h1>');
- exit();
- }
- // Update name to escape special symbols that could allow SQL injection attack
- $grad = $conn->real_escape_string($grad);
- ?>
- <h3>Inserting the $grad: "<?=$grad?>"</h3>
- <?php
- $alt = trim($_REQUEST['alt']);
- echo( "<h3>Inserting (after escaping): $alt</h3>" );
- if( strlen($alt) > 100 || strlen($alt)< 1 ) {
- echo( '<h1>Invalid $alt!</h1>');
- exit();
- }
- // Update name to escape special symbols that could allow SQL injection attack
- $alt = $conn->real_escape_string($alt);
- ?>
- <h3>Inserting the $alt: "<?=$alt?>"</h3>
- <?php
- $problems = trim($_REQUEST['problems']);
- echo( "<h3>Inserting (after escaping): $problems</h3>" );
- if( strlen($problems) > 100 || strlen($problems)< 1 ) {
- echo( '<h1>Invalid $problems!</h1>');
- exit();
- }
- // Update name to escape special symbols that could allow SQL injection attack
- $problems = $conn->real_escape_string($problems);
- ?>
- <h3>Inserting the $$problems: "<?=$problems?>"</h3>
- <?php
- // get the ip address of the requestor
- $ip = $_SERVER['REMOTE_ADDR'];
- $today = date("F j, Y, g:i a");
- $id = 0;
- // Setup the SQL statement
- $sql = "INSERT INTO akash_form_real (id, fname,lname,email,gradyear, alt, problems, datetime, ip)
- VALUES ('$id','$name', '$lname', '$email', '$grad', '$alt', '$problems', '$today','$ip')";
- // Execute the SQL on the server:
- if ($conn->query($sql) === TRUE) {
- echo( '<h3>New record created successfully</h3>' );
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error ;
- }
- // Fun over... close up and go home...
- $conn->close();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement