Jump to content


New Members
  • Content Count

  • Joined

  • Last visited

Posts posted by PatrickG19872019

  1. I'm sorry I don't understand what you mean. Can you please explain this in more detail. This is from a website that shows your how to create a blog from scratch so i don't have any actual experience with php and don't know how to connect properly.

  2. Hello, I am trying to get this website working but i get an error saying invalid data source name.

    I am fairly certain the error isĀ from one of these 2 files.


    function OpenCon()
     $dbhost = "localhost";
     $dbuser = "root";
     $dbpass = "123";
     $db = "db";
     $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);
     return $conn;
    function CloseCon($conn)
     $conn -> close();

    and the other file index.php

    // <? /* php require('includes/db_connection.php'); */ ?>
    <? php include 'db_connection.php'; ?>
    <!DOCTYPE html>
    <html lang="en">
        <meta charset="utf-8">
        <link rel="stylesheet" href="style/normalize.css">
        <link rel="stylesheet" href="style/main.css">
    	<div id="wrapper">
    		<hr />
    $db = null;
    global $stmt;
    			try {
    				// $stmt = db->query('SELECT postID, postTitle, postDesc, postDate FROM blog_posts ORDER BY postID DESC');
    				$conn = new PDO('SELECT postID, postTitle, postDesc, postDate FROM blog_posts ORDER BY postID DESC');
    				while($row = $stmt->fetch()){
    					echo '<div>';
    						echo '<h1><a href="viewpost.php?id='.$row['postID'].'">'.$row['postTitle'].'</a></h1>';
    						echo '<p>Posted on '.date('jS M Y H:i:s', strtotime($row['postDate'])).'</p>';
    						echo '<p>'.$row['postDesc'].'</p>';				
    						echo '<p><a href="viewpost.php?id='.$row['postID'].'">Read More</a></p>';				
    					echo '</div>';
    			} catch(PDOException $e) {
    			    echo $e->getMessage();

    Please help me with this error, I would really like this to work.

    Thank you very much.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.