Jump to content

Includes not being displayed on page


bbram

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.