Advertisement
Guest User

Untitled

a guest
Jan 13th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.23 KB | None | 0 0
  1. <?php
  2. include 'db.php';
  3.  
  4. $query ="SELECT * FROM `product` LIMIT 50";
  5. $result = mysqli_query($connection, $query) or die("Ошибка " . mysqli_error($connection));
  6. if ($result)
  7. {
  8.     $rows = mysqli_num_rows($result); // количество полученных строк
  9.     echo "<style type=\"text/css\">
  10.   TABLE {
  11.    border-collapse: collapse; /* Убираем двойные линии между ячейками */
  12.    width: 650px; /* Ширина таблицы */
  13.   }
  14.   TH, TD {
  15.    border: 1px solid black; /* Параметры рамки */
  16.    text-align: center; /* Выравнивание по центру */
  17.    padding: 4px; /* Поля вокруг текста */
  18.   }
  19.   TH {
  20.    background: #fc0; /* Цвет фона ячейки */
  21.    height: 40px; /* Высота ячеек */
  22.    vertical-align: bottom; /* Выравнивание по нижнему краю */
  23.    padding: 0; /* Убираем поля вокруг текста */
  24.   }
  25.  </style>";
  26.     echo "<table><tr><th>id</th><th>картинка</th><th>подпись</th><th>тема</th><th>текст</th><th>цена</th><th>время</th></tr>";
  27.     for ($i = 0 ; $i < $rows ; ++$i)
  28.     {
  29.         $row = mysqli_fetch_row($result);
  30.         echo "<tr>";
  31.             for ($j = 0 ; $j < 7 ; ++$j) echo "<td>$row[$j]</td>";
  32.         echo "</tr>";
  33.     }
  34.     echo "</table>";
  35.  
  36. }
  37.  
  38.  
  39.  
  40. if(isset($_POST['title']) && isset($_POST['text']) && isset($_POST['price']) && isset($_POST['sign']) && isset($_POST['img'])){
  41.    
  42.     $title = $_POST['title'];
  43.     $text = $_POST['text'];
  44.     $price = $_POST['price'];
  45.     $sign = $_POST['sign'];
  46.     $img = $_POST['img'];
  47.  
  48.    
  49. $result = mysqli_query($connection,"INSERT INTO `product` (`img`, `sign`, `title`, `text`, `price`, `time`)
  50. VALUES ('$img', '$sign', '$title', '$text', '$price', '".time()."');");
  51.  
  52. if ($result == true){
  53.     echo "Информация занесена в базу данных<br>".gmdate("d.m.Y",time());
  54. }else{
  55.     echo "Информация не занесена в базу данных<br>".gmdate("d.m.Y",time());
  56.    
  57. mysqli_free_result($result);
  58.  
  59.     }
  60. }
  61. mysqli_close($connection);
  62.  
  63. #INSERT INTO `product` (`img`, `sign`, `title`, `text`, `price`, `time`)VALUES ('/img/1.jpg', 'sign2', 'text title2', 'full text2', '2333', '2.12.2020');
  64. #SELECT * FROM `product` WHERE id='2' ORDER BY id DESC
  65.  
  66. # enctype="multipart/form-data"
  67.  
  68. ?>
  69.  
  70. <html>
  71. <head>
  72. <title>Запись в БД через форму на php</title>
  73. </head>
  74. <body>
  75. <form  method="POST" action="config.php" enctype="multipart/form-data">
  76. <div align="center"><tr>
  77. <input style="width: 400px;" name="title" type="text" placeholder="Тема"/><br><br>
  78. <textarea style="width: 400px; height: 100px;" name="text" type="text" placeholder="Текст" /></textarea><br>
  79. <input name="price" type="number" placeholder="Цена"/><br>
  80. <input name="img" type="file"/><br>
  81. <input name="sign" type="text" placeholder="Подпись картинки"/><br>
  82. <input type="submit" value="Отправить"/></tr>
  83. </div>
  84. </form>
  85.  
  86. </body>
  87. </html>
  88. <?php
  89.     $imgz = $_FILES['img']['name'];
  90.     $imgz = rand();
  91.     $res = sha1($imgz);
  92.    
  93.     $uploadfile = "screen/".$res.".jpg";
  94.     move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile);
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement