Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> Input page </title>
  4. </head>
  5. <body>
  6. <?php
  7. if($_POST) {
  8.  
  9.     if((!empty($_POST['address') && (!empty($_POST['rent']) && (!empty($_POST['bedrooms'])) {
  10.         $username = "lettings";
  11.         $password = "glass bottle picnic";
  12.         $database = "lettings";
  13.  
  14.         $mysqli = mysqli_connect("localhost", $username, $password, $database);
  15.  
  16.         $address = mysqli_real_escape_string($mysqli, $_POST['address']);
  17.         $rent = mysqli_real_escape_string($mysqli, $_POST['rent']);
  18.         $bedrooms = mysqli_real_escape_string($mysqli, $_POST['bedrooms']);
  19.  
  20.         $query = mysqli_query($mysqli, INSERT INTO contacts VALUES ('', '".$address."', '".$rent."', '".$bedrooms."'));
  21.         mysqli_close($mysqli);
  22.     } else {
  23.         echo "You left a field blank";
  24.     }
  25.  
  26. } else {
  27.     //what to do in the event no post has been recieved at all, could be a blank submission, or could be the first loading of the page
  28. }
  29.  
  30. ?>
  31.  
  32. your html input stuff could go here, because it's not enclosed in either branch of the if above, it'll be displayed whether we made a post or not
  33.  
  34. <form method="post" action=""> <!-- the action="" bit tells the browser to just post back to this page
  35. <input type="text" name="address" id="address" />
  36. <input type="submit" name="submit" value="Insert record" />
  37. </form>
  38. </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement