Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Undeclared variable after require
    primarykey
    data
    text
    <p>I'm trying to make a php site, but I have a problem where I can't use included variables in included files!</p> <p>index.php</p> <pre><code>&lt;?php require 'core/init.php'; ?&gt; </code></pre> <p>init.php</p> <pre><code>&lt;?php require 'config.php'; require 'db/connect.php'; ?&gt; </code></pre> <p>config.php</p> <pre><code>&lt;?php // Config // The Title of the site $site_title = 'php-site'; $site_desc = 'A awesome PHP site!'; $site_keywords = 'php, html5, css3, awesome'; $site_author = 'erty5000'; // Database - MySQL // MySQL host $db_host = 'localhost'; // MySQL username $db_username = 'myuser'; // MySQL password $db_password = 'mypassword'; // MySQL database $db_database = 'mydb'; // Error to display at the top of the page if a connection problem occured $db_connect_error = 'Sorry, we\'re experiencing connection problems.'; ?&gt; </code></pre> <p>connect.php</p> <pre><code>&lt;?php mysql_connect($db_host, $db_username, $db_password) or die($db_connection_error); mysql_select_db($db_database) or die($db_connection_error); ?&gt; </code></pre> <p>The errors I get is</p> <pre><code>Notice: Undefined variable: db_host in C:\xampp\htdocs\w\php-site\core\db\connect.php on line 2 Notice: Undefined variable: db_username in C:\xampp\htdocs\w\php-site\core\db\connect.php on line 2 Notice: Undefined variable: db_password in C:\xampp\htdocs\w\php-site\core\db\connect.php on line 2 Warning: mysql_connect(): Access denied for user ''@'localhost' (using password: NO) in C:\xampp\htdocs\w\php-site\core\db\connect.php on line 2 Notice: Undefined variable: db_connection_error in C:\xampp\htdocs\w\php-site\core\db\connect.php on line 2 </code></pre> <p>Sorry for such a long post, but I'm really hoping someone could help me!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload