{"id":298084,"date":"2020-02-02T15:00:22","date_gmt":"2020-02-02T15:00:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298084"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298084","title":{"rendered":"To-do list \u0437\u0430 5 \u043c\u0438\u043d\u0443\u0442 \u043d\u0430 PHP"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/486624\/\">\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0441\u0435\u0445. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 (To-do list) \u0432\u0441\u0435\u0433\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 PHP, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL. <\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/i.ibb.co\/JrX45kt\/Demo.png\" alt=\"image\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 HTML \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c .php<\/p>\n<p>  <i><b>index.php<\/b><\/i><\/p>\n<pre><code class=\"xml\">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; \t&lt;meta charset=&quot;UTF-8&quot;&gt; \t&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt; \t&lt;title&gt;TO-DO List&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; \t&lt;form action=&quot;add.php&quot; method=&quot;POST&quot;&gt; \t\t&lt;input type=&quot;text&quot; name=&quot;title&quot; required&gt; \t\t&lt;input type=&quot;submit&quot; value=&quot;Add&quot;&gt; \t&lt;\/form&gt; \t \t&lt;ul&gt; \t\t \t&lt;\/ul&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u2014 <i>input type=\u00abtext\u00bb<\/i>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043d\u043e\u043f\u043a\u0443 \u2014 <i>input type=\u00absubmit\u00bb<\/i> \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <i><b>name=\u00abtitle\u00bb<\/b><\/i> \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c.<\/p>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0435\u043c \u0432 <i>phpmyadmin<\/i> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<p>  <b>1. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/i.ibb.co\/k2RSnw5\/Screenshot-1.png\" alt=\"image\"\/><\/p>\n<p>  <b>2. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/i.ibb.co\/5BLjpdx\/Screenshot-2.png\" alt=\"image\"\/><\/p>\n<p>  <b>3. \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/i.ibb.co\/CKJ1NJK\/Screenshot-3.png\" alt=\"image\"\/><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b db.php<\/p>\n<p>  <b>db.php<\/b><\/p>\n<pre><code class=\"php\">&lt;?php  $dsn = 'mysql:host=localhost;dbname=to-do-list'; $pdo = new PDO($dsn, 'root', '');  ?&gt; <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u043a\u0430: <code><i><b>$dsn = 'mysql:host=localhost;dbname=to-do-list';<\/b> <\/i><\/code><br \/>  \u0433\u0434\u0435 <code><b><i>dbname=to-do-list; <\/i><\/b><\/code>\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c add.php<\/p>\n<p>  add.php<\/p>\n<pre><code class=\"php\">&lt;?php   \t\/\/\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \t$title = $_POST['title'];  \t\/\/\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \trequire 'db.php';          \/\/\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445         $sql = 'INSERT INTO list(title) VALUES(:title)';  \t$query = $pdo-&gt;prepare($sql);    \t$query-&gt;execute(['title' =&gt; $title]);          \/\/\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 index.php \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \theader('Location: index.php');  ?&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0438\u0434\u0435\u043c \u0432 index.php<\/p>\n<p>  index.php<\/p>\n<pre><code class=\"xml\"> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; \t&lt;meta charset=&quot;UTF-8&quot;&gt; \t&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt; \t&lt;title&gt;TO-DO List&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; \t&lt;form action=&quot;add.php&quot; method=&quot;POST&quot;&gt; \t\t&lt;input type=&quot;text&quot; name=&quot;title&quot; required&gt; \t\t&lt;input type=&quot;submit&quot; value=&quot;Add&quot;&gt; \t&lt;\/form&gt; \t \t&lt;ul&gt; \t\t&lt;?php                  \/\/\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 db.php \t\trequire 'db.php'; \t\t                 \/\/\u0411\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b list  \t\t$query = $pdo-&gt;query('SELECT * FROM `list` ORDER BY `id` DESC');                                  \/\/\u0426\u0438\u043a\u043b \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \t\twhile($row = $query-&gt;fetch(PDO::FETCH_OBJ)) { \t\t        echo '&lt;div&gt;&lt;li&gt;'. $row-&gt;title .' &lt;a href=&quot;delete.php?id='.$row-&gt;id.'&quot; id=&quot;card-link-click&quot;&gt;X&lt;\/a&gt;&lt;\/li&gt;' . ' &lt;\/div&gt;';  \t\t\t} \t\t ?&gt; \t&lt;\/ul&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0432\u043d\u0443\u0442\u0440\u044c \u0442\u0435\u0433\u0430 <code>ul<\/code> \u043c\u044b \u0432\u0441\u0442\u0430\u0432\u0438\u043b\u0438 php \u043a\u043e\u0434.<\/p>\n<p>  \u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u044d\u0442\u043e delete.php<\/p>\n<p>  delete.php<\/p>\n<pre><code class=\"php\"> &lt;?php   \/\/\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 db.php require 'db.php';  \/\/\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f $id = $_GET['id'];  \/\/\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b list \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c id   $sql = 'DELETE FROM `list` WHERE `id` = ?';   $query = $pdo-&gt;prepare($sql);   $query-&gt;execute([$id]);  \/\/\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c\u0441\u044f \u0432 index.php   header('Location: index.php');   ?&gt;  <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f.<\/p>\n<p>  style.css<\/p>\n<pre><code class=\"css\">body { \tpadding: 40px; }  input[type=&quot;text&quot;] { \twidth: 330px; \theight: 40px; \tborder: 1px solid #c4c4c4; \tborder-radius: 5px 0 0 5px; \tborder-right: none; \tpadding-left: 10px; \tpadding-right: 10px; }  input[type=&quot;submit&quot;] { \twidth: 80px; \theight: 44px; \tbackground: #3F6BDE; \tborder: none;  \tposition: absolute; \tborder: 1px solid #c4c4c4; \tborder-radius: 0 5px 5px 0; }  ul { \tlist-style: none; \tpadding-left: 0; }  li { \twidth: 400px; \theight: auto; \tborder: 2px solid gray; \tpadding-top: 20px; \tlist-style: none;     padding: 15px;     margin-bottom: 10px;     background: #fcfcfc;     border: 1px solid silver;     border-radius: 5px;\t }  a {     float: right;     text-decoration: none;     color: red; }  <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e.<\/p>\n<p>  \u0418\u0442\u043e\u0433\u043e, \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 \u0438\u043b\u0438 To-do list \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 PHP.<\/p>\n<p>  <b>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e:<\/b><\/p>\n<p>  <a href=\"https:\/\/drive.google.com\/file\/d\/1PJimzOouACrcgjTebktkycTk1bN8dQbU\/view?usp=sharing\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a \u043a \u0443\u0440\u043e\u043a\u0443<\/a>.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/486624\/\"> https:\/\/habr.com\/ru\/post\/486624\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/486624\/\">\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0441\u0435\u0445. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 (To-do list) \u0432\u0441\u0435\u0433\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 PHP, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL. <\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/i.ibb.co\/JrX45kt\/Demo.png\" alt=\"image\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-298084","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=298084"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298084\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}