Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Our database connection
- $conn = mysqli_connect("localhost", "root", "root", "lesson_03");
- var_dump($_POST);
- $sql="INSERT into countries(
- name,
- description,
- population
- )values(
- ' {$_POST['name']}',
- '{$_POST['description']}',
- {$_POST['population']}
- )";
- echo $sql;
- // Query out database providing our connection and our SQL
- $res = mysqli_query($conn, $sql);
- // Perform some derpy error handling
- if ($res) {
- // We're successful
- echo "The new country was created succesfully";
- } else {
- // We failed miserably
- echo "There was an error creating this country" . mysqli_error($conn);
- }
- ?>
- <!DOCTYPE html>
- <head>
- <title>Adding Countries</title>
- </head>
- <body>
- <!-- The form for creating a new country -->
- <form action = "<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
- <div>
- <label>Country Name:</label>
- <input name="name">
- </div>
- <div>
- <label>Country Description:</label>
- <textarea name="description"></textarea>
- </div>
- <div>
- <label>Country Population:</label>
- <input name="population" type="number">
- </div>
- <button type="submit">Create</button>
- <form>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement