I am doing a little homework assignment in which we are making a very rudimentary CMS. We are to fill in a form containing title, body, permalink. The CMS then takes the permalink, and adds it to the main nav bar. When that permalink is clicked on the navbar, the title, content, datestamp created and datestamp modified are to be displayed.
I have that stuff working, only problem is that when I click on the nav link,
I receive this notice:
Notice: Constant DB_HOST already defined in C:\Program
Files\xampp\htdocs\php\assignment_6\config.php on line 2Notice: Constant DB_USER already defined in C:\Program
Files\xampp\htdocs\php\assignment_6\config.php on line 3Notice: Constant DB_PASS already defined in C:\Program
Files\xampp\htdocs\php\assignment_6\config.php on line 4Notice: Constant DB_NAME already defined in C:\Program
Files\xampp\htdocs\php\assignment_6\config.php on line 5
I have a config.php file that I use to establish a DB connection:
<?php
define('DB_HOST','******');
define('DB_USER','******');
define('DB_PASS','******');
define('DB_NAME','******');
$cms_db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!$cms_db){
echo"Could not connect: ".mysql_error();
}
?>
Here is the code from the file calling config.php causing this notice:
<?php
require('config.php');
$perm = $_GET['p'];
$query = "SELECT * FROM cms WHERE permalink = '$perm'";
$result = $cms_db->query($query);
$row = $result->fetch_assoc();
$page_title = $perm;
require('header.php');
?>
<h1><?=$row['title'];?></h1>
<hr/><br/>
<p class="para"><?=$row['content']?></p>
<?php require('footer.php');?>
A small amount of simple code, but what is the problem? It is not a fatal error but it is annoying.
You’re probably including config.php multiple times. Check all your scripts and find this duplicity. You can use
require_once()instead ofrequire()to prevent this.