Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. // Our database connection
  4. $conn = mysqli_connect("localhost", "root", "root", "lesson_03");
  5. var_dump($_POST);
  6. $sql="INSERT into countries(
  7. name,
  8. description,
  9. population
  10. )values(
  11. ' {$_POST['name']}',
  12. '{$_POST['description']}',
  13. {$_POST['population']}
  14. )";
  15. echo $sql;
  16.  
  17. // Query out database providing our connection and our SQL
  18. $res = mysqli_query($conn, $sql);
  19.  
  20. // Perform some derpy error handling
  21. if ($res) {
  22. // We're successful
  23. echo "The new country was created succesfully";
  24. } else {
  25. // We failed miserably
  26. echo "There was an error creating this country" . mysqli_error($conn);
  27. }
  28.  
  29. ?>
  30.  
  31. <!DOCTYPE html>
  32. <head>
  33. <title>Adding Countries</title>
  34. </head>
  35.  
  36. <body>
  37. <!-- The form for creating a new country -->
  38. <form action = "<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
  39. <div>
  40. <label>Country Name:</label>
  41. <input name="name">
  42. </div>
  43. <div>
  44. <label>Country Description:</label>
  45. <textarea name="description"></textarea>
  46. </div>
  47. <div>
  48. <label>Country Population:</label>
  49. <input name="population" type="number">
  50. </div>
  51.  
  52. <button type="submit">Create</button>
  53. <form>
  54. </form>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement