Working version:
Uses Ajax to ping GetBrowseData.php which includes Connection.php. Connection.php has a variable $CardTable defined and GetBrowseData.php uses that correctly.
GetBrowseData.php
Code: Select all
<?php
include("Enums.php");
include("Connection.php");
$sqlConnection = OpenConnection();
mysql_query( $CardTable, $sqlConnection ) or mysql_error(); // Works, $CardTable is valid
...
?>
Code: Select all
<?php
$CardTableName = "MyTableName";
$CardTable = "CREATE TABLE ".$CardTableName." (
rowID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(rowID),
Name varchar(30)
)";
function OpenConnection()
{
$sqlConnection = mysql_connect( blah blah ); // Removed from this example for obvious reasons
if( !$sqlConnection )
{
die( 'Could not connect: ' . mysql_error() );
}
mysql_select_db( blah blah );
return $sqlConnection;
}
?>
Code: Select all
<form id="Data" action = "CreateState.php?userEntry=writeData" method = "post">
CreateState.php
Code: Select all
<html>
<body onload="OnLoad();">
<?php
include( "Enums.php" );
include( "Header.php" );
include( "CreateCard.php" );
?>
...
<?php
// User selected the CreateCard button
if( isset($_GET['userEntry']) && $_GET['userEntry'] == "writeData" )
{
CreateCard();
}
// New user
if( !isset($_GET['userEntry']) )
{
?>
<form id="Data" action = "CreateState.php?userEntry=writeData" method = "post">
...
// Above form calls it's own file with the writeData when they press submit.
CreateCard.php
Code: Select all
<?php
include( "Enums.php" );
include( "Connection.php" );
function CreateCard()
{
echo $CardTable; // Fails, gives me Notice: Undefined variable.
$sqlConnection = OpenConnection();
}
Does anyone know what might cause it to fail to find $CardTable in this instance?