Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title> Input page </title>
- </head>
- <body>
- <?php
- if($_POST) {
- $username = "lettings";
- $password = "glass bottle picnic";
- $database = "lettings";
- $mysqli = mysqli_connect("localhost", $username, $password, $database);
- if((!empty($_POST['address') && (!empty($_POST['rent']) && (!empty($_POST['bedrooms'])) {
- $address = mysqli_real_escape_string($_POST['address']);
- $rent = mysqli_real_escape_string($_POST['rent']);
- $bedrooms = mysqli_real_escape_string($_POST['bedrooms']);
- } else {
- echo "You left a field blank";
- }
- $query = mysqli_query($mysqli, INSERT INTO contacts VALUES ('', '".$address."', '".$rent."', '".$bedrooms."'));
- mysqli_close($mysqli);
- } else {
- //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
- }
- ?>
- 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
- <form method="post" action=""> <!-- the action="" bit tells the browser to just post back to this page
- <input type="text" name="address" id="address" />
- <input type="submit" name="submit" value="Insert record" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement