<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>Главная</title>
</head>
<body>
<form method="post" action="city_add.php">
<input class="input" type="text" name="answer">
<h5>Введите площадь:</h5>
<input class="input" type="text" name="plosh">
<h5>Введите количество населения:</h5>
<input class="input" type="text" name="naselen">
<br>
<br>
<input type="submit" name="input_button" value="Добавить">
<input type="submit" name="clear">
</form>
<h5>Введите город:</h5>
<form action="city_view.php" method="GET">
<input type="text" name="name">
<input type="submit" name="viewbutton" value="Просмотреть">
</form>
<?php
if (isset($_SESSION['nety'])) {
echo $_SESSION['nety'];
unset($_SESSION['nety']);
}
?>
<table>
<tr>
<td>
<?php
if (isset($_SESSION['name'])) {
print_r($_SESSION['name']) ;
} else {
echo $_SESSION['nety'];
}
?>
</td>
<td>
<?php
if (isset($_SESSION['area'])) {
echo ($_SESSION['area']);
}else {
echo $_SESSION['nety'];
}
?>
</td>
<td>
<?php
if (isset($_SESSION['population'])) {
echo ($_SESSION['population']);
} else {
echo $_SESSION['nety'];
}
?>
</td>
</tr>
</table>
<?php
if(isset($_SESSION['arr'])) :?>
<table>
<tr>
<th>id</th>
<th>name</th>
<th>area</th>
<th>population</th>
</tr>
<?php foreach ($_SESSION['arr'] as $gorod) : ?>
<tr>
<td><?php echo $gorod['id']; ?></td>
<td><?php echo $gorod['name']; ?></td>
<td><?php echo $gorod['area']; ?></td>
<td><?php echo $gorod['population']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php unset($_SESSION['arr']); ?>
<?php endif; ?>
<?php
if(isset($_POST['clear'])) {
session_destroy();
}
?>
</body>
</html>
<?php foreach ($_SESSION['arr'] as $gorod) : ?>
<tr>
<td><?php echo $gorod['id']; ?></td>
<td><?php echo $gorod['name']; ?></td>
<td><?php echo $gorod['area']; ?></td>
<td><?php echo $gorod['population']; ?></td>
</tr>
<?php endforeach; ?>
} else if (empty($name)) {
$mysql = "SELECT * FROM city";