require_once buggy?

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
chopficaro
Forum Commoner
Posts: 68
Joined: Fri Jan 01, 2010 12:56 am

require_once buggy?

Post 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>
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: require_once buggy?

Post 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
chopficaro
Forum Commoner
Posts: 68
Joined: Fri Jan 01, 2010 12:56 am

Re: require_once buggy?

Post 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
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: require_once buggy?

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: require_once buggy?

Post 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
Dorin85
Forum Newbie
Posts: 20
Joined: Tue Aug 16, 2011 3:16 pm

Re: require_once buggy?

Post 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.
Post Reply