Page 1 of 1

DB_HOST Connection problem?

Posted: Tue Sep 25, 2007 5:30 am
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);



?>

Posted: Tue Sep 25, 2007 5:49 am
by superdezign
Hmm. Are you sure that this particular config.php is in the same folder as tools.class.php?

Posted: Tue Sep 25, 2007 6:01 am
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

Posted: Tue Sep 25, 2007 6:14 am
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';
	
	
	}

Posted: Tue Sep 25, 2007 8:02 am
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/') ;

Posted: Tue Sep 25, 2007 8:11 am
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>';

Posted: Tue Sep 25, 2007 8:51 am
by maddenuk
Thanks for the response but im unsure what you mean as the filename is 'config.php' and is in lowercase?

Cheers

Posted: Tue Sep 25, 2007 12:09 pm
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.