Page 1 of 1

require_once buggy?

Posted: Wed Aug 17, 2011 7:36 pm
by chopficaro
i was just trying to move my database log in information from my incex files to a config file, and when i did it gave me errors saying the variables i set in it were undefined undefined

it definitely found the file because i used require once

then i put the variables back into the index files and suddenly everything was ok, but i want the varibles in the config file!

yankeeconfig.php

Code: Select all

<?
	define("DB_SERVER", "localhost");
	define("DB_USER", "root");
	define("DB_PASS", "p");
	define("DB_NAME", "yankee_customers");
?>
yankeecustomerdatabase.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>create tables to accept yankee screen client order forms</title>
</head>
<body>
<p>
html working
 
<?php
// change variables when changing servers
	require_once "yankeeconfig.php";  
	define("DB_SERVER", "localhost");
	define("DB_USER", "root");
	define("DB_PASS", "p");
	define("DB_NAME", "yankee_customers");
// confirm variables at run time
echo DB_SERVER;
echo DB_USER;
echo DB_PASS;
echo DB_NAME;
 
// connect to server and select database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $con) or die(mysql_error());
 
// create table
$q="CREATE TABLE orders 
(
	ordernum int NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name varchar(30),
	phone varchar(32),
	email varchar(50),
	otherinfo varchar(3200),
	timestamp TIMESTAMP(8)
);";
 
// confirm table column names at run time
echo $q;
 
// punch it chewey
$result = mysql_query($q,$con);
 
// confirm table or return error at run time
if($result)
{
	echo "table created";
}
else
{
	echo mysql_error();
};
 
?>
</p></body></html>

Re: require_once buggy?

Posted: Wed Aug 17, 2011 7:50 pm
by twinedev
Based on the code you have, my guess would be that you are on a server that does not allow short tags ( <? .... ?> ) and required full tags ( <?php .... ?> )

The included file WAS there, but PHP didn't recognize your short tags, so it didn't process any code between them

-Greg

Re: require_once buggy?

Posted: Wed Aug 17, 2011 9:31 pm
by chopficaro
danm ur right that was the problem
thanks bro
thats pretty strange because im running the server on my own machine with windows 7 64 and the latest version of wamp server
i hope i dont run into any more stupidness like this, i thought wamp was a respectable program package
thanks again i really appreciate ur help

Re: require_once buggy?

Posted: Thu Aug 18, 2011 7:35 am
by phphelpme
It is but you can setup your server to accept long or short code. It just depends which one is set as default thats all in your php.ini files.

Best wishes

Re: require_once buggy?

Posted: Thu Aug 18, 2011 2:06 pm
by twinedev
The default value since php5 I think it was is to not accept short tags, while many places will change that back to be "backward compatible".

I myself prefer the full tags, except, I'll admit, i do miss the echo shortcut of <?= $variable ?> instead of <?php echo $vairable; ?>

-Greg

Re: require_once buggy?

Posted: Thu Aug 18, 2011 3:17 pm
by Dorin85
A friend of mine had this issue recently. He had 50+ files with short open tags.

php.ini contains "short_open_tag" toggling this fixed the problem, as opposed to modifying 50+ files.

http://php.net/manual/en/ini.core.php

PS: The captcha for new users can be incredibly hard to read.