DB_HOST Connection problem?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

DB_HOST Connection problem?

Post by maddenuk »

I keep getting this error from my code when im trying to execute my script.
ERRNO:, 8 TEXT : Use of undefined constant DB_HOST - assumed 'DB_HOST' LOCATION: /home/sites/waphoo.net/public_html/classes/tools.class.php, line 14
I'm unsure what the problem is? Any advice or hints?

Thanks

CONFIG.PHP

Code: Select all

<?

//define database connection values

define("DB_HOST", 'localhost');
define("DB_USER", '*****');
define("DB_PASSWORD", '******');
define("DB_DATABASE", '******');



?>
TOOLS.CLASS.PHP

Code: Select all

<?php
require_once('config.php');


class Tools

{
	private $mMysqli;
	
	//constructor opens database connection
	
	function __construct() {
	
	$this->mMysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
	
	}
	
	//destructor closes database connection
	
	function __destruct() {
	
	$this->mMysqli->close();
	
	}
	
	
	/*
	* Function registers users values into database and sends off 
	* an email to both the user and Core Telecom
	*/
	public function register($name, $house_number, $street, $town, $city, $postcode, $country, $telephone, $mobile, $email)
	{

	$query = $this->mMysqli->query("INSERT into requests VALUES (NULL,'$telephone', '$mobile' , '$email' , 'NULL', '$name','$house_number' , '$street', '$town', '$city', '$postcode', '$country')");
	$this->sendCoreEmail($email, $name);
	$this->sendUserEmail($email, $name);
	//return 'www.waphoo.net';
	
	
	}
	
	
	
	
	private function sendCoreEmail($email, $name)
	{
	
	$sender = 'Waphoo';
	$time_of_enquiry = date('r');
	$recipient = 'martinsandhu@gmail.com';
	$headers = "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
	$headers .= "X-Mailer: php\n";
	$headers .= 'From: Waphoo <'.$sender.'>';
	$subject = "Waphoo -  New Number Request";
	$mail = '
	
	A new user has requested for a number to be mapped at waphoo.
	
	Name: '.$name.'
	Email: '.$email.'
	
	To view information and send this user a number. Login to the Waphoo Control Panel.
	
	http://www.waphoo.net/admin/
	
			
	
	Regards,
	Waphoo 
		
			
			';
			
			$result = mail($recipient, $subject, $mail, $headers); 
	
	
	
	}
	
	
	
	
	private function sendUserEmail($email, $name)
	{
	
	$sender = 'Waphoo';
	$time_of_enquiry = date('r');
	$recipient = $email;
	$headers = "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
	$headers .= "X-Mailer: php\n";
	$headers .= 'From: Waphoo <'.$sender.'>';
	$subject = "Waphoo -  Your New Number Request";
	$mail = '
	
	Hello '.$name.'
	
	Thanks for requesting your own personal international follow me telephone number.
	
	A member of our team will be in touch within the next 24 hours to guide you through the setup and your number.
			
	
	Regards,
	Waphoo 
		
			
			';
			
			$result = mail($recipient, $subject, $mail, $headers); 
	
	
	
	}
}

?>
REGISTER.PHP

Code: Select all

<?php

require_once('classes/tools.class.php');
require_once('classes/error_handler.php');

$name = $_POST['name'];
$house_number = $_POST['house_number'];
$street = $_POST['street'];
$town = $_POST['town'];
$mobile = $_POST['mobile'];
$city = $_POST['city'];
$country = $_POST['country'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$postcode = $_POST['postcode'];

$tools = new Tools();

$tools->register($name, $house_number, $street, $town, $city, $postcode, $country, $telephone, $mobile, $email);



?>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Hmm. Are you sure that this particular config.php is in the same folder as tools.class.php?
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Post by maddenuk »

Yes it is.

I've just put the code from the config.php into the tools.class.php and it works.

However this is unsuitable so i assume its a problem with the require_once() ?

Cheers
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Post by maddenuk »

Also i've got a question about using 'return'?

The line doesn't seem to execute in my script? I'm unsure why?

Code: Select all

public function register($name, $house_number, $street, $town, $city, $postcode, $country, $telephone, $mobile, $email)
	{

	$query = $this->mMysqli->query("INSERT into requests VALUES (NULL,'$telephone', '$mobile' , '$email' , 'NULL', '$name','$house_number' , '$street', '$town', '$city', '$postcode', '$country')");
	$this->sendCoreEmail($email, $name);
	$this->sendUserEmail($email, $name);
	return './index.html';
	
	
	}
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Return returns a value from a function

Code: Select all

function test()
{
   return 'neeble' ;
}

$nobble = test() ;

echo $nobble ; // prints neeble
I think you are trying to do a redirect, that would be this

Code: Select all

// redirect to cnn.com
header( 'Location: http://www.cnn.com/') ;
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Your include is in all lowercase, and you named config in all Caps, this could be a problem if its a *nix server.

Put this under your include..

Code: Select all

$Defines = get_defined_constants(true);
print '<pre>'; print_r ($Defines['user']); print '</pre>';
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Post by maddenuk »

Thanks for the response but im unsure what you mean as the filename is 'config.php' and is in lowercase?

Cheers
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

maddenuk wrote:Thanks for the response but im unsure what you mean as the filename is 'config.php' and is in lowercase?

Cheers
In your original post you have it in all caps.

Did you put that code under the include? If you did it should print all of your Defined Variables.
Post Reply