Created
October 15, 2015 20:00
-
-
Save VictorFursa/ec60a9a1e0866b10cbe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Города</title> | |
| </head> | |
| <body> | |
| <form method="POST" action="city.php"> | |
| Город: <br> | |
| <input type="text" name="city"/><br> | |
| Область:<br> | |
| <input type="text" name="area"/><?php $area = $_POST['area'] ?> <br> | |
| <input type="submit" name="add" value="Добавить"/><br> | |
| <input type="submit" name="search" value="Искать"/><br> | |
| </form> | |
| <?php | |
| mysql_connect("localhost","root","") | |
| or die('Не удалось соединиться: ' . mysql_error()); | |
| mysql_select_db("alcohol") | |
| or die('Не удалось выбрать базу данных'); | |
| mysql_set_charset("utf8"); | |
| if(isset ($_POST['add'])) { | |
| $city = strip_tags(trim($_POST['city'])); | |
| $area = strip_tags(trim($_POST['area'])); | |
| mysql_query(" | |
| INSERT INTO city(city,area) | |
| VALUES('$city','$area') | |
| "); | |
| echo "Город успешно добавлен!"; | |
| } | |
| if(isset($_POST['search'])){ | |
| if(isset($_POST['area'])){ | |
| $result = mysql_query("SELECT * FROM city WHERE area = '$area' "); | |
| while($row = mysql_fetch_array($result)){ | |
| echo $row['city']."<br>"; | |
| } | |
| } | |
| } | |
| mysql_close(); | |
| ?> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment