0

I went to view page source and seen this in the HTML for a select drop-down list that is populated by a query:

Notice: Constant DB_USER already defined in C:\xampp\htdocs\bookhippie\mysqli_connect.php on line 8

Notice: Constant DB_PASSWORD already defined in C:\xampp\htdocs\bookhippie\mysqli_connect.php on line 9

Notice: Constant DB_HOST already defined in C:\xampp\htdocs\bookhippie\mysqli_connect.php on line 10

Notice: Constant DB_NAME already defined in C:\xampp\htdocs\bookhippie\mysqli_connect.php on line 11

Should I be concerned about this? And if so, what should I be looking for in the PHP?

Thanks!

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
JNoel
  • 7
  • 3
  • 6
    Yes you should be concerned. The specific errors mean that constants are being redefined, probably because some file is being included twice (use `include_once()/require_once()` instead) If you can see the errors, your users can too, and you risk exposing info about your underlying source code. – Michael Berkowski Jan 10 '14 at 02:46
  • 1
    If the site is in production, you should disable `display_errors` in `php.ini`, or at runtime with `ini_set('display_errors', 1);` at the top of the code. In development, it's important to see and _correct_ all those errors, but they must be hidden from your users. – Michael Berkowski Jan 10 '14 at 02:51

2 Answers2

2

Yes, you should always worry over notices being generated by your code. PHP is trying to tell you that it thinks you've done something wrong, but can't be sure what it is.

In your case, I'm assuming you're using require instead of require_once.

user229044
  • 232,980
  • 40
  • 330
  • 338
1

You should always strive to write code that produces zero errors including notices. This will help you prevent unexpected behavior and make sure PHP is performant.

In your case you either are including a file multiple times or are trying to define a constant multiple times. In the first case you need to switch from include()/require() to include_once()/require_once(). In the latter you need to check if the constant is defined before trying to define it again.

defined('DB_USER') || define('DB_USER', 'your value');
John Conde
  • 217,595
  • 99
  • 455
  • 496