Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> Input page </title>
  4. </head>
  5. <body>
  6. <?php
  7. if($_POST) {
  8.     $username = "lettings";
  9.     $password = "glass bottle picnic";
  10.     $database = "lettings";
  11.  
  12.     $mysqli = mysqli_connect("localhost", $username, $password, $database);
  13.  
  14.     if((!empty($_POST['address') && (!empty($_POST['rent']) && (!empty($_POST['bedrooms'])) {
  15.         $address = mysqli_real_escape_string($_POST['address']);
  16.         $rent = mysqli_real_escape_string($_POST['rent']);
  17.         $bedrooms = mysqli_real_escape_string($_POST['bedrooms']);
  18.     } else {
  19.         echo "You left a field blank";
  20.     }
  21.  
  22.     $query = mysqli_query($mysqli, INSERT INTO contacts VALUES ('', '".$address."', '".$rent."', '".$bedrooms."'));
  23.     mysqli_close($mysqli);
  24. } else {
  25.     //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
  26. }
  27.  
  28. ?>
  29.  
  30. 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
  31.  
  32. <form method="post" action=""> <!-- the action="" bit tells the browser to just post back to this page
  33. <input type="text" name="address" id="address" />
  34. <input type="submit" name="submit" value="Insert record" />
  35. </form>
  36. </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement