fork download
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Гостевая книга</title>
  5. <meta charset="UTF-8">
  6. </head>
  7. <body>
  8. <?php
  9. $user = 'test';
  10. $password = 'test';
  11. $db = new PDO('mysql:host=127.0.0.1;dbname=testdb;charset=UTF8', $user, $password);
  12.  
  13.  
  14. $stmt = $db->query('SELECT username, message FROM posts');
  15.  
  16. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  17. $username = htmlspecialchars($row['username']);
  18. $message = htmlspecialchars($row['message']);
  19.  
  20. echo "<div style='margin-bottom: 10px;'>
  21. <div>$username</div>
  22. <div>$message</div>
  23. </div>";
  24. }
  25.  
  26. $db = null;
  27. ?>
  28.  
  29. <form method="POST" action="/create.php">
  30. <div>
  31. <label>Введите Ваше имя:</label><br>
  32. <input type="text" name="username">
  33. </div>
  34.  
  35. <div>
  36. <label>Введите сообщение:</label><br>
  37. <input type="text" name="message">
  38. </div>
  39.  
  40. <input type="submit" name="okbutton" value="Отправить">
  41. </form>
  42. </body>
  43. </html>
Runtime error #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
<!DOCTYPE HTML>
<html>
    <head>
        <title>Гостевая книга</title>
        <meta charset="UTF-8">
    </head>
    <body>
        
stderr
PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /home/9adbtp/prog.php:11
Stack trace:
#0 /home/9adbtp/prog.php(11): PDO->__construct('mysql:host=127....', 'test', 'test')
#1 {main}
  thrown in /home/9adbtp/prog.php on line 11