3v4l.org

run code in 300+ PHP versions simultaneously
<!DOCTYPE html> <?php global $db; $sqliteerror = null; try{ $db = new PDO('sqlite:mysqlitedb.sqlite3'); } catch(Exception $e){ echo htmlentities($e->getMessage()); echo "<br><br><br>"; die('Error opening or creating new sqlite DB. Check write permissions for '.dirname(__FILE__)); } //Save if(isset($_POST['answer']) && trim($_POST['answer'])){ $sql = 'INSERT INTO survey (answer) VALUES (\''.$_POST['answer'].'\')'; $db->query($sql); } ?> <html> <head> <title></title> </head> <body> <fieldset> <legend>SURVEY: What is the best food?</legend> <form method="POST"> <label>Answer: <input type="text" name="answer"></label> <input type="submit"> </form> </fieldset> <fieldset> <legend>SURVEY: Previous Answers</legend> <?php $sql = 'SELECT COUNT(*) as x, `answer` FROM survey WHERE `answer` != \'\' GROUP BY `answer`'; foreach ($db->query($sql) as $row) { echo $row['x'] . "x ".$row['answer'].'<br>'; } ?> </fieldset> </body> </html>

preferences:
56.37 ms | 402 KiB | 5 Q