Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_host='localhost';
- $db_name='dergunov';
- $db_user='dergunov';
- $db_pass='neto1055';
- mysql_connect($db_host,$db_user,$db_pass);
- mysql_select_db($db_name);
- mysql_set_charset('utf8');
- $result=mysql_query('SELECT * FROM `tasks`');
- if (isset($_POST["description"]) AND !empty($_POST["description"])) {
- $desc = $_POST["description"];
- $sql = mysql_query("INSERT INTO `tasks` (`description`, `is_done`, `date_added`) VALUES ('$desc', '0', now())");
- if ($sql) {
- header ("location: http://university.netology.ru/u/dergunov/dz11/task.php");
- } else {
- echo "<p>Произошла ошибка.</p>";
- }
- };
- if (isset($_GET['del'])) {
- $sql = mysql_query('DELETE FROM `tasks` WHERE `ID` = "'.$_GET['del'].'"');
- if ($sql) {
- header ("location: http://university.netology.ru/u/dergunov/dz11/task.php");
- } else {
- echo "<p>Произошла ошибка.</p>";
- }
- }
- if (isset($_GET['done'])) {
- $sql = mysql_query('UPDATE `tasks` SET `is_done` = "1" WHERE `ID` = "'.$_GET['done'].'"');
- if ($sql) {
- header ("location: http://university.netology.ru/u/dergunov/dz11/task.php");
- } else {
- echo "<p>Произошла ошибка.</p>";
- }
- }
- ?>
- <div>
- <form action="" method="POST">
- <input type="text" name="description" placeholder="Описание задачи" value="" />
- <input type="submit" name="save" value="Добавить" />
- </form>
- </div>
- <table border="1" cellpadding="8" cellspacing="0">
- <tr>
- <th>Описание задачи</th>
- <th>Дата добавления</th>
- <th>Статус</th>
- <th>Управление</th>
- </tr>
- <?php
- while ($row = mysql_fetch_assoc($result)) {
- $id = $row['id'];
- $name = $row['description'];
- $date = $row['date_added'];
- $done = $row['is_done'];
- echo "<tr><td>$name</td><td>$date</td><td>";
- if ($done == 0) {
- echo 'В процессе';
- } else {
- echo 'Выполнено';
- };
- echo "</td><td>
- <a href='?done=$id'>Выполнить</a>
- <a href='?del=$id'>Удалить</a>
- </td></tr>";
- }
- ?>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment