Advertisement
Guest User

country

a guest
Jul 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. $result1 = $mysqli1->query("SELECT * FROM country where country ='$country' ") or die
  2. ($mysqli1 -> error);
  3. $result2 = $mysqli1->query("SELECT * FROM city where country ='$country' AND city
  4. ='$city' ") or die ($mysqli1 -> error);
  5. while($row1=$result1 -> fetch_assoc())
  6. {
  7. while($row2=$result2 -> fetch_assoc())
  8. {
  9. if (mysqli_num_rows($result1) > 0) {
  10. if (mysqli_num_rows($result2) > 0) {
  11. echo '<p>Ця країна та місто вже існують! Продовжимо у ';
  12. echo $row1['country'];
  13. echo ' ';
  14. echo $row2['city'];
  15. echo '</p>';
  16. }
  17. else {
  18. echo '<p>Ця країна вже існує! Ми додали це місто в цю країну!</p>';
  19. $insert_row1 = $mysqli1->query("INSERT INTO city (country, city) VALUES('$country',
  20. '$city' )") or die ($mysqli1 -> error);
  21. }
  22. }
  23. else {
  24. $insert_row = $mysqli1->query("INSERT INTO country (country) VALUES('$country' )")
  25. or die ($mysqli1 -> error);
  26. $insert_row1 = $mysqli1->query("INSERT INTO city (country, city) VALUES('$country',
  27. '$city' )") or die ($mysqli1 -> error);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement