Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dbhost = 'localhost';
- $dbuser = 'root';
- $dbpass = '';
- $db = 'world';
- $conn = new mysqli($dbhost, $dbuser, $dbpass, $db);
- if (isset($_GET['dodaj'])) {
- $code = $_GET['code'];
- $name = $_GET['name'];
- $continent = $_GET['continent'];
- $region = $_GET['region'];
- $sql = "SELECT code FROM `country` WHERE code = '$code'";
- $search = $conn->query($sql);
- $row = $search->fetch_assoc();
- if($row['code'] == $code){
- echo "Istnieje już państwo o takim kodzie";
- }else{
- $sql = " INSERT INTO `country` (`Code`, `Name`, `Continent`, `Region`) VALUES ('".$code."', '".$name."', '".$continent."', '".$region."')";
- if ($conn->query($sql) === TRUE) {
- echo "Dodano nowy rekord";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }
- ?>
- <!Doctype html>
- <html>
- <meta charset="utf-8">
- <body>
- <form action="zadanie3.php" method="GET">
- <label>Code</label><input type="text" name="code"><br>
- <label>Name</label><input type="text" name="name"><br>
- <label>Continent</label>
- <select name="continent">
- <option value="Asia">Asia</option>
- <option value="Europe">Europe</option>
- <option value="North America">North America</option>
- <option value="Africa">Africa</option>
- <option value="Oceania">Oceania</option>
- <option value="Antarctica">Antarctica</option>
- <option value="South America">South America</option>
- </select><br>
- <label>Region</label><input type="text" name="region"><br>
- <input type="submit" name="dodaj" value="dodaj">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement