bbram Posted July 5, 2020 Share Posted July 5, 2020 I have a very simple page, where I use the include statement that includes my connection string. The connection string and a variables are not being passed to my test server - (WAMP). My include file is below $server = "servername"; $username = "username"; $password = ""; $database = "dbname"; $portNumber = 3308; $link = mysqli_connect($server,$username,$password,$database,$portNumber); if(!$link) { echo "cannot connet to the server"; } else { echo "This works"; } echo "Hi"; I am including this file with the following code: include ("includes/connect.inc"); My site is not connecting to the database, and is not displaying "This works", or "Hi". Do you have any pointers on how to get this connect? Quote Link to comment https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page/ Share on other sites More sharing options...
gw1500se Posted July 5, 2020 Share Posted July 5, 2020 Did you check your httpd log? Do you have all error reporting turned on? I'm guessing that the path in the include is wrong. error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page/#findComment-1579382 Share on other sites More sharing options...
mac_gyver Posted July 5, 2020 Share Posted July 5, 2020 4 hours ago, bbram said: I use the include statement use 'require' for things your code must have for it to work. this will stop code execution if the required file could not be found and prevent follow-on errors in code trying to use things that don't exist. 4 hours ago, bbram said: My include file is below do you have an opening <?php tag in the file? 4 hours ago, bbram said: connect.inc use a .php extension for this file. by using .inc for the extension, anyone can browse to the file and get the raw php code in it, exposing your database connection credentials. by using a .php extension, the php code would instead be executed if someone browsed to it and they cannot see the raw php code. Quote Link to comment https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page/#findComment-1579384 Share on other sites More sharing options...
bbram Posted July 6, 2020 Author Share Posted July 6, 2020 I changed the file name to connect.php I do have <? and ?> in my connect file I also changed to use the following require 'includes/connect.php'; I also added echo $server and my page is telling me that i have an undefined error Still I am not sure what the problem is Quote Link to comment https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page/#findComment-1579391 Share on other sites More sharing options...
mac_gyver Posted July 6, 2020 Share Posted July 6, 2020 1 hour ago, bbram said: I do have <? that's not what i posted. php's short opening php tag may not be enabled and shouldn't be used anyway. what does the 'view source' in your browser of the main page show? Quote Link to comment https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page/#findComment-1579393 Share on other sites More sharing options...
bbram Posted July 6, 2020 Author Share Posted July 6, 2020 Ok I saw what you meant...I added <?php to the front and was getting an error message. I apparently changed my DB name sometime and forgot to update code. Thanks for helping with this. Quote Link to comment https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page/#findComment-1579408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.