Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'db.php';
- $query ="SELECT * FROM `product` LIMIT 50";
- $result = mysqli_query($connection, $query) or die("Ошибка " . mysqli_error($connection));
- if ($result)
- {
- $rows = mysqli_num_rows($result); // количество полученных строк
- echo "<style type=\"text/css\">
- TABLE {
- border-collapse: collapse; /* Убираем двойные линии между ячейками */
- width: 650px; /* Ширина таблицы */
- }
- TH, TD {
- border: 1px solid black; /* Параметры рамки */
- text-align: center; /* Выравнивание по центру */
- padding: 4px; /* Поля вокруг текста */
- }
- TH {
- background: #fc0; /* Цвет фона ячейки */
- height: 40px; /* Высота ячеек */
- vertical-align: bottom; /* Выравнивание по нижнему краю */
- padding: 0; /* Убираем поля вокруг текста */
- }
- </style>";
- echo "<table><tr><th>id</th><th>картинка</th><th>подпись</th><th>тема</th><th>текст</th><th>цена</th><th>время</th></tr>";
- for ($i = 0 ; $i < $rows ; ++$i)
- {
- $row = mysqli_fetch_row($result);
- echo "<tr>";
- for ($j = 0 ; $j < 7 ; ++$j) echo "<td>$row[$j]</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- if(isset($_POST['title']) && isset($_POST['text']) && isset($_POST['price']) && isset($_POST['sign']) && isset($_POST['img'])){
- $title = $_POST['title'];
- $text = $_POST['text'];
- $price = $_POST['price'];
- $sign = $_POST['sign'];
- $img = $_POST['img'];
- $result = mysqli_query($connection,"INSERT INTO `product` (`img`, `sign`, `title`, `text`, `price`, `time`)
- VALUES ('$img', '$sign', '$title', '$text', '$price', '".time()."');");
- if ($result == true){
- echo "Информация занесена в базу данных<br>".gmdate("d.m.Y",time());
- }else{
- echo "Информация не занесена в базу данных<br>".gmdate("d.m.Y",time());
- mysqli_free_result($result);
- }
- }
- mysqli_close($connection);
- #INSERT INTO `product` (`img`, `sign`, `title`, `text`, `price`, `time`)VALUES ('/img/1.jpg', 'sign2', 'text title2', 'full text2', '2333', '2.12.2020');
- #SELECT * FROM `product` WHERE id='2' ORDER BY id DESC
- # enctype="multipart/form-data"
- ?>
- <html>
- <head>
- <title>Запись в БД через форму на php</title>
- </head>
- <body>
- <form method="POST" action="config.php" enctype="multipart/form-data">
- <div align="center"><tr>
- <input style="width: 400px;" name="title" type="text" placeholder="Тема"/><br><br>
- <textarea style="width: 400px; height: 100px;" name="text" type="text" placeholder="Текст" /></textarea><br>
- <input name="price" type="number" placeholder="Цена"/><br>
- <input name="img" type="file"/><br>
- <input name="sign" type="text" placeholder="Подпись картинки"/><br>
- <input type="submit" value="Отправить"/></tr>
- </div>
- </form>
- </body>
- </html>
- <?php
- $imgz = $_FILES['img']['name'];
- $imgz = rand();
- $res = sha1($imgz);
- $uploadfile = "screen/".$res.".jpg";
- move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement