Advertisement
akvem

Untitled

Oct 3rd, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.05 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4.    
  5.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
  6.  
  7.        
  8.    
  9.         $('#test').click(function() {
  10.  
  11.              $.ajax({
  12.               type: "POST",
  13.               url: "some.php",
  14.               data: { name: "John" }
  15.             }).done(function( msg ) {
  16.               alert( "Data Saved: " + msg );
  17.             });    
  18.  
  19.         });
  20.    
  21.     </script>
  22.    
  23.    
  24.     <style>
  25.    
  26.         body, html {
  27.             height: 100%;
  28.             background-color: azure;
  29.             font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  30.            
  31.         }
  32.        
  33.         #first{
  34.             background-color: bisque;
  35.             border: 5;
  36.             padding: 7px;
  37.         }
  38.        
  39.         #second{
  40.             background-color: cornsilk;
  41.             padding: 7px;
  42.         }
  43.         td{
  44.             padding: 8px;
  45.         }
  46.         tr:hover {
  47.             background-color:deepskyblue;
  48.         }
  49.        
  50.        
  51.         #test {
  52.            
  53.             /*
  54.             Formatting taken from
  55.             https://www.jotform.com/help/118-How-to-Customize-the-Submit-Button-with-CSS
  56.             */
  57.  
  58.             background: #422bd8;
  59.  
  60.             color: white;
  61.  
  62.             border-style: outset;
  63.  
  64.             border-color: #422bd8;
  65.  
  66.             height: 30px;
  67.  
  68.             width: 100px;
  69.  
  70.             font: bold 15px arial, sans-serif;
  71.  
  72.             text-shadow:none;
  73.         }
  74.        
  75.    
  76.    
  77.    
  78.     </style>
  79.    
  80.    
  81.    
  82.    
  83.    
  84.    
  85.    
  86.    
  87. <meta charset="utf-8">
  88. <title>Akash insertion</title>
  89. </head>
  90.  
  91. <body>
  92.  
  93.     <div id="second">
  94.         <h1 id="Intro"> Hello </h1>
  95.        
  96.         <h3>This is a survey meant to gauge your experience with the Surface Pro 4</h3>
  97.        
  98.         <form action="sql insert php.php" method="post">
  99.        
  100.         <fieldset>
  101.  
  102.            
  103.             <table>
  104.            
  105.                 <tr>
  106.                     <td><label for="fName">First Name: </label></td>
  107.                     <td><input name="fname" type="text" id="fName"></td>
  108.                 </tr>
  109.                 <tr>
  110.                     <td><label for="lName">Last Name: </label></td>
  111.                     <td><input name="lname" type="text" id="lName"></td>
  112.                 </tr>
  113.                 <tr>
  114.                     <td><label for="email">Email: </label></td>
  115.                     <td><input name="loginName" type="email" id="email"></td>
  116.                 </tr>
  117.                 <tr>
  118.                     <td><label for="gradYear">Grad Year:</label></td>
  119.                     <td> <input type="radio" name="grad" value="2019"> 2019<br> </td>
  120.                     <td> <input type="radio" name="grad" value="2020"> 2020<br> </td>
  121.                     <td> <input type="radio" name="grad" value="2021"> 2021<br> </td>
  122.                     <td> <input type="radio" name="grad" value="2022"> 2022<br> </td>
  123.                 </tr>
  124.  
  125.             </table>
  126.        
  127.         </fieldset>
  128.            
  129.         <fieldset>
  130.            
  131.             <table>
  132.            
  133.  
  134.                 <tr>
  135.                     <td><label for="talt">Which one of these alternatives would you prefer</label></td>
  136.                     <td> <input type="radio" name="alt" value="mac"> Macbook Pro<br> </td>
  137.                     <td> <input type="radio" name="alt" value="ipad"> Ipad Pro<br> </td>
  138.                     <td> <input type="radio" name="alt" value="slaptop"> Surface Laptop<br> </td>
  139.                     <td> <input type="radio" name="alt" value="xps"> Dell XPS<br> </td>
  140.                 </tr>
  141.                 <tr>
  142.                     <td><label for="paroblems">Have you had any problems with your Surface so far:</label></td>
  143.                     <td> <input type="radio" name="problems" value="yes"> Yes<br> </td>
  144.                     <td> <input type="radio" name="problems" value="no"> No<br> </td>
  145.                 </tr>
  146.  
  147.                 <br>
  148.                
  149.             </table>
  150.        
  151.         <input type="submit" name="action" value="GO">
  152.        
  153.         </fieldset>
  154.            
  155.         <!-- I would add more if I had time -->
  156.  
  157.            
  158.         </form>
  159.    
  160.    
  161.    
  162.    
  163.    
  164.     </div>
  165.    
  166.     <div>
  167.     <br>
  168.     <br>
  169.     <br>
  170.     <br>
  171.     <br>
  172.     <br>
  173.     <br>
  174.     <br>
  175.     <br>
  176.     <br>
  177.     <br>
  178.     <br>
  179.     <br>
  180.     <br>
  181.     <br>
  182.     <br>
  183.     <br>
  184.     <br>
  185.     <br>
  186.     <br>
  187.     <br>
  188.     <br>
  189.     <br>
  190.     <br>
  191.     <br>
  192.     <br>
  193.     <br>
  194.     <br>
  195.     <br>
  196.     <br>
  197.     <br>
  198.     <br>
  199.     <br>
  200.     <br>
  201.     <br>
  202.     <br>
  203.     <br>
  204.     <br>
  205.     <br>
  206.     <br>
  207.    
  208.  
  209.    
  210.    
  211.    
  212.    
  213.    
  214.     </div>
  215.    
  216.    
  217.    
  218.    
  219.    
  220.     <?php
  221.  
  222.     if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['action']))
  223.     {
  224.        
  225.         foreach ($_POST as $key => $value) {
  226.             echo "<tr>";
  227.             echo "<td>";
  228.             echo $key;
  229.             echo "</td>";
  230.             echo "<br>";
  231.  
  232.             echo "<td>";
  233.             echo $value;
  234.             echo "</td>";
  235.             echo "</tr>";
  236.            
  237.                         echo "<br>";
  238.                         echo "<br>";
  239.  
  240.         }
  241.         insert();
  242.     }
  243.  
  244.    
  245. function abc(){
  246.     echo "The  function is called.";
  247.  
  248. }
  249.    
  250.    
  251.    
  252. function insert($name){
  253.  
  254.     $servername = "localhost";
  255.     $username = "playground18";
  256.     $password = "Cdz5SOVrY2p8fnWS";
  257.     $dbname = "playground18";
  258.  
  259.  
  260.     // Create connection
  261.     $conn = new mysqli($servername, $username, $password, $dbname);
  262.     // Check connection
  263.     if ($conn->connect_error) {
  264.         die("Connection failed: " . $conn->connect_error);
  265.     }
  266.     echo( "<h3>Connected to $dbname</h3>");
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.     $name = trim($_REQUEST['fname']);
  282.     echo( "<h3>Inserting (after escaping): $name</h3>" );
  283.     if( strlen($name) > 100 || strlen($name)< 1 ) {
  284.         echo( '<h1>Invalid name!</h1>');
  285.         exit();
  286.     }
  287.  
  288.     // Update name to escape special symbols that could allow SQL injection attack
  289.     $name = $conn->real_escape_string($name);
  290.     ?>
  291.         <h3>Inserting the name: "<?=$name?>"</h3>
  292.     <?php
  293.        
  294.        
  295.        
  296.        
  297.        
  298.        
  299.     $lname = trim($_REQUEST['lname']);
  300.     echo( "<h3>Inserting (after escaping): $lname</h3>" );
  301.     if( strlen($lname) > 100 || strlen($lname)< 1 ) {
  302.         echo( '<h1>Invalid name!</h1>');
  303.         exit();
  304.     }
  305.  
  306.     // Update name to escape special symbols that could allow SQL injection attack
  307.     $lname = $conn->real_escape_string($lname);
  308.     ?>
  309.         <h3>Inserting the lname: "<?=$lname?>"</h3>
  310.     <?php
  311.        
  312.     echo
  313.     $email = trim($_REQUEST['loginName']);
  314.     echo( "<h3>Inserting (after escaping): $email</h3>" );
  315.  
  316.  
  317.     // Update name to escape special symbols that could allow SQL injection attack
  318.     $email = $conn->real_escape_string($email);
  319.     ?>
  320.         <h3>Inserting the email: "<?=$email?>"</h3>
  321.     <?php
  322.        
  323.        
  324.     $grad = trim($_REQUEST['grad']);
  325.     echo( "<h3>Inserting (after escaping): $grad</h3>" );
  326.     if( strlen($grad) > 100 || strlen($grad)< 1 ) {
  327.         echo( '<h1>Invalid $grad!</h1>');
  328.         exit();
  329.     }
  330.  
  331.     // Update name to escape special symbols that could allow SQL injection attack
  332.     $grad = $conn->real_escape_string($grad);
  333.     ?>
  334.         <h3>Inserting the $grad: "<?=$grad?>"</h3>
  335.     <?php
  336.            
  337.        
  338.        
  339.        
  340.         $alt = trim($_REQUEST['alt']);
  341.     echo( "<h3>Inserting (after escaping): $alt</h3>" );
  342.     if( strlen($alt) > 100 || strlen($alt)< 1 ) {
  343.         echo( '<h1>Invalid $alt!</h1>');
  344.         exit();
  345.     }
  346.  
  347.     // Update name to escape special symbols that could allow SQL injection attack
  348.     $alt = $conn->real_escape_string($alt);
  349.     ?>
  350.         <h3>Inserting the $alt: "<?=$alt?>"</h3>
  351.     <?php
  352.        
  353.        
  354.        
  355.             $problems = trim($_REQUEST['problems']);
  356.     echo( "<h3>Inserting (after escaping): $problems</h3>" );
  357.     if( strlen($problems) > 100 || strlen($problems)< 1 ) {
  358.         echo( '<h1>Invalid $problems!</h1>');
  359.         exit();
  360.     }
  361.  
  362.     // Update name to escape special symbols that could allow SQL injection attack
  363.     $problems = $conn->real_escape_string($problems);
  364.     ?>
  365.         <h3>Inserting the $$problems: "<?=$problems?>"</h3>
  366.     <?php
  367.            
  368.    
  369.    
  370.     // get the ip address of the requestor
  371.     $ip = $_SERVER['REMOTE_ADDR'];
  372.    
  373.     $today = date("F j, Y, g:i a");
  374.     $id = 0;
  375.  
  376.     // Setup the SQL statement
  377.     $sql = "INSERT INTO akash_form_real (id, fname,lname,email,gradyear, alt, problems, datetime, ip)
  378.    VALUES ('$id','$name', '$lname', '$email', '$grad', '$alt', '$problems', '$today','$ip')";
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.     // Execute the SQL on the server:
  394.     if ($conn->query($sql) === TRUE) {
  395.         echo( '<h3>New record created successfully</h3>' );
  396.     } else {
  397.         echo "Error: " . $sql . "<br>" . $conn->error ;
  398.     }
  399.  
  400.     // Fun over... close up and go home...
  401.     $conn->close();
  402.  
  403. }
  404.  
  405. ?>
  406.  
  407.  
  408.  
  409. </body>
  410. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement