PHP mysql_query fails after page reload
Posted: Mon Jun 18, 2012 6:19 pm
Hello Everyone. I really try to figure things out before asking. Please HELP I'm into this 2 days now.
I've abbreviated the entire code to what must be relevant replicating the exact error from the full program.
Here it is with the issue commented on line #24
I've abbreviated the entire code to what must be relevant replicating the exact error from the full program.
Here it is with the issue commented on line #24
Code: Select all
<?php
function renderform($notice) {
?>
<html>
<head>
<title></title>
</head>
<body>
<div id="container">
<?php
if($notice != '') {
echo '<div style="padding:4px; border:1px solid red; color:red;">' . $notice . '</div>';
unset($notice);
}
?>
<form action= "" method="post">
<input type="radio" name="filter" id="filter" value="flyin" /> Flyin
<?php
include_once 'Connect_Db.php';
/* * * Above include works fine when page loads, on Submit it fails with following message:
Undefined variable: MemberDbTableName in C:\wamp\www\public_html\BmfMemberDbFiles\debug.php on line 43
The below is the contents of 'Connect_Db.php'
When I run it instead of above include_once 'Connect_Db.php';
It works without fail everytime all day long.
$server = 'localhost';
$user = 'user';
$pass = 'password';
$db = 'test';
$MemberDbTableName = 'members_beta';
$connection = mysql_connect($server, $user, $pass)
or die ("Could not connect to server ... \n" . mysql_error ());
mysql_select_db($db)
or die ("Could not connect to database ... \n" . mysql_error ());
*/
$result = mysql_query("SELECT *
FROM $MemberDbTableName
WHERE type='flyin'
GROUP BY EXTRACT(YEAR FROM dues_paid) ") or die($result."<br/><br/>".mysql_error());
if(is_resource($result)) {
echo '<select name="select_flyin_year">';
while($row = mysql_fetch_array($result)) {
$select_flyin_year = date('Y', strtotime($row['dues_paid']));
echo '<option value="' . $select_flyin_year . '">' . $select_flyin_year;
}
echo '</select>';
}
?>
<br />
<input type="radio" name="filter" id="filter" value="all" /> All<br />
<textarea rows="12" cols="70" name="message" id="message"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
</div>
</body>
</html>
<?php
}
if (isset($_POST['submit'])) {
if (!empty($_POST['message'])) { //do some stuff
}
else {
$error = "Check form for Error!";
renderform($error);
}
if (!isset($error)) {
include_once 'Connect_Db.php';
//perform query
renderform('success');
}
}
else { //the form hasn't been submitted
renderform('');
}
?>