Advertisement
Guest User

Untitled

a guest
Apr 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. $dbhost = 'localhost';
  3. $dbuser = 'root';
  4. $dbpass = '';
  5. $db = 'world';
  6.  
  7. $conn = new mysqli($dbhost, $dbuser, $dbpass, $db);
  8.  
  9. if (isset($_GET['dodaj'])) {
  10. $code = $_GET['code'];
  11. $name = $_GET['name'];
  12. $continent = $_GET['continent'];
  13. $region = $_GET['region'];
  14.  
  15.  
  16. $sql = "SELECT code FROM `country` WHERE code = '$code'";
  17. $search = $conn->query($sql);
  18. $row = $search->fetch_assoc();
  19. if($row['code'] == $code){
  20. echo "Istnieje już państwo o takim kodzie";
  21. }else{
  22. $sql = " INSERT INTO `country` (`Code`, `Name`, `Continent`, `Region`) VALUES ('".$code."', '".$name."', '".$continent."', '".$region."')";
  23.  
  24. if ($conn->query($sql) === TRUE) {
  25. echo "Dodano nowy rekord";
  26. } else {
  27. echo "Error: " . $sql . "<br>" . $conn->error;
  28. }
  29. }
  30.  
  31.  
  32. ?>
  33.  
  34. <!Doctype html>
  35. <html>
  36. <meta charset="utf-8">
  37. <body>
  38. <form action="zadanie3.php" method="GET">
  39. <label>Code</label><input type="text" name="code"><br>
  40. <label>Name</label><input type="text" name="name"><br>
  41. <label>Continent</label>
  42. <select name="continent">
  43. <option value="Asia">Asia</option>
  44. <option value="Europe">Europe</option>
  45. <option value="North America">North America</option>
  46. <option value="Africa">Africa</option>
  47. <option value="Oceania">Oceania</option>
  48. <option value="Antarctica">Antarctica</option>
  49. <option value="South America">South America</option>
  50. </select><br>
  51. <label>Region</label><input type="text" name="region"><br>
  52. <input type="submit" name="dodaj" value="dodaj">
  53. </form>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement