Need help with selection lists

Hey everyone. I’m new to php and I’m having trouble getting some work done. I’m supposed to be making a game involving U.S. presidents and their years in office. A random set of years is displayed, and the user has to pick out a president from a drop down list. I’ve got most of it done, but I am having trouble with getting it to evaluate the submission and tell the user whether it is right or wrong. Right now it sees every answer as wrong. Also, I need the output to display in the table at the bottom, but it seems like the if-else statement for it needs to remain where it is, but that prints out at the top. Anyway here is the code, I appreciate any help you can give.

[php][/php]

<?php require_once "include/Session.php"; $session = new Session(); if (!isset($session->valid)) { // user hasn't validated $target = $_SERVER['REQUEST_URI']; // where I'm trying to go require_once "login.php"; // forward request to login.php exit(); } require_once "include/presidents.php"; // this is the list of all terms $terms = array_keys($pres_terms); // this is the list of all names (duplicates removed) // sorted by last name $pres_names = array_unique(array_values($pres_terms)); usort($pres_names, "byLastName"); $params = (object) $_REQUEST; print_r($params); if (isset($params->guess)) { $pres_term = $params->pres_term; $answer = $params->answer; $num = $params->num; $term = $params->term; $old_answer = $answer; if ($old_answer == $answer) { ++$num; } $choices->pres_term[$pres_term] = "selected"; if ($params->guess == $pres_term) { echo "That is correct\n"; } else { echo "Sorry, wrong guess #$num\n"; } } else { $term = $terms[ mt_rand( 0, count($terms)-1 ) ]; $answer = $term; $num = 0; } ?>

[/php]

U.S. President Guess Game #logout { position: absolute; top: 10px; right: 10px; } table { border-style: solid; padding: 0px 0px 10px 0px; margin-top: 10px; width: 500px; height: 200px; background: #F4F4F4; } td { overflow: hidden; border-style: solid; } body { font-family: arial; background: #3A3838; } Start Over

U.S. President Guessing Game

During this term: <?php echo $answer ?>

	<form action="" method="post">
		<input type="hidden" name="answer" value="<?php echo $answer?>" />
		<input type="hidden" name="term" value="<?php echo $term?>" />
		<input type="hidden" name="num" value="<?php echo $num?>" />
	 
	  Who was the U.S. President?:
	  <select name="pres_term">
	  <?php foreach ($pres_names as $pres_term): ?>
		<option <?php echo $choices->pres_term[$pres_term] ?>  ><?php echo $pres_term?></option>
	  <?php endforeach ?>
	  </select>
	  <input type="submit" name="guess" value="Guess" />
	</form>
	</td>
</tr>
<?php
echo $pres_terms[$term]
?>
[/code]

Nevermind. Fixed it.

Sponsor our Newsletter | Privacy Policy | Terms of Service