require_once buggy?
Posted: Wed Aug 17, 2011 7:36 pm
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
yankeecustomerdatabase.php
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");
?>
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>