0

I have decided its time to get my website changed to mysqli (finally).

I have started with the very first piece on my website. Its already not going the way I want it to. Could you try point me in the right direction and then this should help with the remainder of the website.

This is my db_connect file I think I have done it right:

<?php
$db = new mysqli('localhost', 'name', 'password', 'table');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
?>

This is at the top of each page where it needs to connect:

<?php
require("db_connect.php");
$todaysdate = date("d/m/Y");
?>

This is the code:

<?  
                      $sql = <<<SQL
                      SELECT *
                      FROM 'events'
                      WHERE 'active' = 1
                SQL;

                if(!$result = $db->query($sql)){
                    die('There was an error running the query [' . $db->error . ']');
                }
                while($row = $result->fetch_assoc()){
                    echo $row['date'] . '<br />';
                    echo $row['title'] . '<br />';
                    echo $row['location'] . '<br />';
                    echo $row['link'] . '<br />';
                }
                ?>

I have played around with this and unable to get it working. I would appreciate any input.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

0 Answers0