Jump to content

Tyler7028

New Members
  • Posts

    6
  • Joined

  • Last visited

Tyler7028's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It is as if the variable just doesn't go anywhere after.
  2. I did this. and this is what happens. array (size=2) 'answers' => array (size=6) 0 => null 1 => null 2 => null 3 => null 4 => null 5 => string 'g' (length=1) I entered at least a letter/number in each of them.
  3. Yah, each question is being submitted on a form (pages), but they don't go along, so it has to do with the way I am declaring my $answerOne ... and so on variables?
  4. It seems when I run the program I want at the end to display all of the inputted answers, but for some reason it won't display.
  5. Hi everybody, I created a trivia game which lets the user answer questions. So far I have created a skeleton version of it. The problem I am having is my variables are not saving in an array - the way I would like them to. I have a session array created. Also if you are using it the questions aren't answered yet. Here is my code : <html> <head> <title>Trivia</title> </head> <?php //Hides non-harmful errors error_reporting(E_ALL ^ E_NOTICE); //Gets the content from the question text file $file = $_SERVER['DOCUMENT_ROOT'] . "/class/Assignment1/questions.txt"; $contents = file($file); //Session Start session_start(); $answerOne = $_POST['answerOne']; $answerTwo = $_POST['answerTwo']; $answerThree = $_POST['answerThree']; $answerFour = $_POST['answerFour']; $answerFive = $_POST['answerFive']; $answerSix = $_POST['answerSix']; //Declaring my session variables for answers/questions $_SESSION['answers'] = array($answerOne, $answerTwo, $answerThree, $answerFour, $answerFive, $answerSix); $_SESSION['contents'] = array($contents[0], $contents[1], $contents[2], $contents[3], $contents[4], $contents[5]); $answerArray = $_SESSION['answers']; $questionsArray = $_SESSION['contents']; //Declaring my variables $answer = "answerOne"; $text = "text"; $submit = "submit"; $questions = $questionsArray[0]; //If the button is clicked. if (isset($_POST['submit']) == true ){ $clickCount = intval($_POST['clickCount']); $clickCount += 1; $questions = $questionsArray[1]; //If the clickCount = 1 if($clickCount == 1){ $answer = "answerTwo"; //If the clickCount = 2 }if($clickCount == 2){ $answer = "answerThree"; $questions = $questionsArray[2]; //if the clickCount = 3 }if($clickCount == 3){ $answer = "answerFour"; $questions = $questionsArray[3]; //If the clickCount = 4 }if($clickCount == 4){ $answer = "answerFive"; $questions = $questionsArray[4]; //If the clickCount = 5 }if($clickCount == 5){ $answer = "answerSix"; $questions = $questionsArray[5]; //If the clickCount = 6 }if($clickCount == 6){ $text = "hidden"; $submit = "hidden"; $questions = ""; print_r($answerArray) . "<br />"; } } ?> <body> <form action="trivia1.php" method="post"> <input type="hidden" name="clickCount" value="<?php echo $clickCount; ?>"> <label><?php echo $questions; ?></label> <input type="<?php echo $text; ?>" name="<?php echo $answer; ?>"> <input type="<?php echo $submit; ?>" name="submit"> </form> </body> </html>
  6. //declaring variables $answerOne = $_POST['answer1']; $answerTwo = $_POST['answer2']; $answerThree = $_POST['answer3']; $answerFour = $_POST['answer4']; $answerFive = $_POST['answer5']; $answerSix = $_POST['answer6']; //declaring my cookies $exp = time()+86400; setcookie("answer1text", $answerOne, $exp); setcookie("answer2text", $answerTwo, $exp); setcookie("answer3text", $answerThree, $exp); setcookie("answer4text", $answerFour, $exp); setcookie("answer5text", $answerFive, $exp); setcookie("answer6text", $answerSix, $exp); I have 6 different questions coming from a text document. I am trying to display the cookies, but they keep disappearing once I move through the different forums. Does anyone know why they keep disappearing I am using the developer tools and they are going through but only stay on one page. <tr> <td><?php echo $contents[0]; ?></td><td>The sub-marine</td><td><?php echo $answerOne; ?> </tr> they look like such. 6 of these. I will upload the files as well. questions.txt trivia.php
×
×
  • 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.