fork download
  1. //index.php
  2. <?php
  3. require_once ('config.php');
  4. $queryResult = mysqli_query($link, "SELECT * FROM posts");
  5. $headersNumber = $queryResult -> num_rows;
  6. $posts = array();
  7.  
  8. for ($i=0; $i<$headersNumber; $i++) {
  9. $posts[] = mysqli_fetch_assoc($queryResult);
  10. }
  11.  
  12. include_once('view.html');
  13. ?>
  14.  
  15.  
  16. //post.php
  17. <?php
  18. if (isset($_POST['text'])) {
  19. $text = htmlspecialchars($_POST['text']);
  20.  
  21. if (!empty($_POST['username'])) {
  22. $username = htmlspecialchars($_POST['username']);
  23. } else {
  24. $username = "Аноним";
  25. }
  26.  
  27. unset($_POST['username']);
  28. unset($_POST['text']);
  29. require_once ('config.php');
  30. $queryResult = mysqli_query($link, "INSERT INTO `microboard`.`posts` (`name`, `message`) VALUES ('$username', '$text')");
  31. }
  32. header('Location: /index.php');
  33. ?>
  34.  
  35.  
  36. //config.php
  37. <?php
  38. $db = array('host' => 'localhost',
  39. 'user' => 'root',
  40. 'pass' => '',
  41. 'name' => 'microboard');
  42. $link = mysqli_connect($db['host'], $db['user'], $db['pass'], $db['name']);
  43. ?>
  44.  
  45.  
  46. //view.html
  47.  
  48. <!DOCTYPE html>
  49. <html>
  50.  
  51. <head>
  52. <title>Microboard</title>
  53. </head>
  54.  
  55. <body>
  56. <?php
  57. $num = count($posts);
  58. for($i=0; $i<$headersNumber; $i++) {
  59. echo "<p><b>№{$posts[$i]['id']}";
  60. echo "{$posts[$i]['name']}";
  61. echo "{$posts[$i]['posttime']}";
  62. echo "</b><br>";
  63. echo "{$posts[$i]['message']}";
  64. echo "</p><hr>";
  65. }
  66. ?>
  67.  
  68. <form method="post" action="/post.php">
  69. Name:
  70. <input type="text" name="username">
  71. <br>
  72. Комментарий:<br>
  73. <textarea type="text" name="text" rows="3" cols="64" required></textarea>
  74. <br>
  75. <input type="submit" value="Отправить пост">
  76. </form>
  77.  
  78. </body>
  79.  
  80. </html>
  81.  
  82.  
Runtime error #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
//index.php
stderr
PHP Warning:  require_once(config.php): failed to open stream: No such file or directory in /home/kKdP36/prog.php on line 4
PHP Fatal error:  require_once(): Failed opening required 'config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/kKdP36/prog.php on line 4