I wanted to make posts and comments system.
Posts worked fine, but comments had
PHP error: Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in C:\xampp\htdocs\index.php:133 Stack trace: #0 C:\xampp\htdocs\index.php(133): PDO->__construct('localhost', 'root', '') #1 {main} thrown in C:\xampp\htdocs\index.php on line 133. `
$db = new PDO ("localhost", "root", ""); $query = $db->prepare("SELECT * FROM comments"); $query->execute(); while($fetch = $query->fetch(PDO::FETCH_ASSOC)){ $name = $fetch['name']; $message = $fetch['comment']; echo "<li class='com'><b>".ucwords($name)."</b> - ".$message."</li>"; } It's element of table. Please help.