Jump to content

By submit button wont work


genome

Recommended Posts

2rhkxdw.png

 

<?php

require_once "include/Session.php";

$session = new Session();

if (!isset($session->valid)) {

  require_once "login.php";

  exit();

}

require_once "include/presidents.php";

 

// this is the list of the terms

$terms = array_keys($term_presidents); 

 

// this is the list of all names (duplicates removed), sorted by last name

$presidents = array_unique(array_values($term_presidents));

usort($presidents, "byLastName");

 

/* DO NOT MODIFY THE ABOVE LINES !!!!! */

 

$params = (object) $_REQUEST;

print_r($params);

 

$session->$terms = $terms;

 

 

/* Remaining Php handler code goes here  */

 

if (isset($params->guess)) {

  $answer = $session->answer;

  $term   = $session->term;

  $presidents = $params->presidents;

 

  $wrong = $session->wrong;

 

  $old_answer = $answer;

 

   if ($answer == $old_answer) {

      $wrong += 1;

   }

   $session->wrong = $wrong;

 

 

   $session->answer = $answer;

   $response = "Sorry wrong guess # $wrong .";


else {

  // choose a random word

  $term = $terms[ mt_rand( 0, count($terms)-1 ) ];

  $session->$term = $term;

 

  $wrong = 0;

  $session->wrong = $wrong;

}

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 



<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge"/>

<title>Average Calculator</title>

<style type="text/css">

body {

  padding: 20px;

}

#logout {

  position: absolute;

  top: 40px;

  right: 40px;

}

 

form {

 margin: 10px 0;

}

.spacing {

  letter-spacing: .5em;

/* Add more style rules */

 

</style>

</head>

<body>

 

<a id="logout" href="logout.php">Log out</a>

<a id =<?php echo $president;?></a>

 

<h2>President Guesss Game</h2>

 

<form action="program.php" method="get">

  <button type="submit" name="reset" >New Game</button>

</form>

<!-- Add form and presentation code -->

 

During the term

<pre> 

<?php echo $term?>

<pre>

 who was the U.S President?

 

 

  <select name="presidents">

  <?php foreach ($presidents as $value): ?>

    <option <?php if ($value == $params->presidents) echo "selected" ?>  

       ><?php echo $value?></option>

  <?php endforeach ?>

  

  </select>

  <input type="submit" name="guess" value="Guess" />

  

</form>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/286745-by-submit-button-wont-work/
Share on other sites

nothing is being submitted because you don't have an opening <form ... > tag for the select menu.

 

i'm pretty sure they still teach 'estimating' in math classes, where you estimate the magnitude of the answer you expect so that you know if the work you are doing is even in the correct 'ball-park' to produce the result you expect? the same concept applies in programming. you must have an idea what result (in this case a html form) you are trying to produce is supposed to look like so that you know the work you are doing is going to produce the result you expect.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.