[SOLVED] Disappearing Variable

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
mattmcb
Forum Commoner
Posts: 27
Joined: Sun Jan 25, 2004 3:34 pm

[SOLVED] Disappearing Variable

Post by mattmcb »

I need some help, for some reason only the SELECT form type has a problem when I process the form twice. All the other variables continue to appear no matter how many times I process the form except for the SELECT types. I can process the form once and it stays, but twice and it's gone.

Please check out the code and let me know what you think:

*The variable is month1

Code: Select all

if (!isset($_POST['month1'])) $_POST['month1'] = '';

// function to output form and hold previously entered values.
function user_form() {

// now to output the form HTML.
echo ('
<form method="post" action="'.htmlspecialchars($_SERVER['PHP_SELF']).'">');
if (!$_POST['month1']){
echo ('
&nbsp;<select name="month1"><option value="">[Select One]<option value="January">January<option value="February">February<option value="March">March<option value="April">April<option value="May">May<option value="June">June<option value="July">July<option value="August">August<option value="September">September<option value="October">October<option value="November">November<option value="December">December</select>&nbsp;
');}else{
echo htmlspecialchars($month1);
} 
');
}

// has the form been submitted?
if (isset($_POST['submit'])) {
    // the form has been submitted
    // perform data checks.
	//POST Contract Variables
	$month1 = $_POST['month1'];
	
	//Strip Slashes from Contract Variables
	$month1 = stripslashes(month1);
	
	}
	               //Error checking here
                               // Show the form again!
		user_form();
		exit(); // if the error checking has failed, we'll exit the script!
	}
}else {
    // the form has not been submitted, let's show it
    user_form();
}
feyd|for future reference, please use

Code: Select all

tags when posting php code.[/color]
mattmcb
Forum Commoner
Posts: 27
Joined: Sun Jan 25, 2004 3:34 pm

Post by mattmcb »

Nevermind... I'm an idiot. I wasn't saving the variable each time... I was just printing it out and not capturing it again.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that was easy to solve :P
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

your elite feyd
Post Reply