Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // mysqli(хост, пользователь, пароль_пользователя, название_БД)
- $connect = new mysqli("localhost", "root", "", "managerarticle");
- $connect->query("SET NAMES 'utf8'");
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Сайтик</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <link href="layout/style.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
- </head>
- <body>
- <div id="wrap">
- <div id="header">
- <div id="logo">Редактор статей по технологии Ajax</div>
- <div id="nav">
- <ul>
- <li class="active"><a href="index.php">Главная страница</a></li>
- </ul>
- </div>
- <div id="header-pic"> <img src="info/header-pics/index-header.jpg" alt="" /> </div>
- </div>
- <div id="content-wrap">
- <div id="content">
- <h1> Редактор товаров</h1>
- <div>
- Добавить товар:<br>
- <input type="text" id="ids" name="article_title_new" placeholder="Название товара">
- <input type="button" name="addArticle" value="Добавить новый товар"><br>
- </div><br>
- <table border="0" cellspacing="0" cellpadding="0">
- <caption>
- Товары
- </caption>
- <tr>
- <th >Номер товара</th>
- <th>Название</th>
- <th>Редактирование</th>
- </tr>
- <?php
- // достаем из базы данных ID и заголовок всех статей
- $result = $connect->query("select article_id, article_title from article");
- //определяем количество полученных записей
- $colResult = $result->num_rows;
- if($colResult > 0)
- {
- for($i = 0; $i < $colResult; $i++)
- {
- $row = $result->fetch_object();
- echo"<tr>";
- echo "<td>".$row->article_id."</td>";
- echo "<td>".$row->article_title."</td>";
- echo "<td><center><input type='checkbox' name='delete_button[]' value='".$row->article_id."'></center></td>";
- echo "</tr>";
- }
- }
- ?>
- </table>
- </div>
- <script type="text/javascript" >
- $(document).ready( function()
- {
- // обрабатываем событие нажатия на кнопку "Добавить новый товар"
- $('input[name=addArticle]').click(
- function ()
- {
- var article_title = $('input[name=article_title_new]').val();
- // отправляем AJAX запрос
- $.ajax(
- {
- type: "POST",
- url: "index.php",
- data: "article_title=" + article_title,
- success: function(response)
- {
- if(response == "OK")
- {
- alert("Товар " + article_title + " добавлен!");
- location.reload();
- }
- else
- alert("" + response);
- }
- }
- );
- }
- );
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement