Jump to content

trevzilla

New Members
  • Posts

    7
  • Joined

  • Last visited

trevzilla's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That was it! Thanks so much. Didn't realize that line was sending info to the browser.
  2. So I have a site in which a user logs in. When they click the submit button on the login page, it checks to see if a username and password combo exists in an array. If it doesn't exist, the user is supposed to be redirected back to the login page. This code USED to work, and I think I added one thing completely away from the code that should do any of this, but now it doesn't work any more. I've read that you can't have anything output before the header code, so I've double checked, and can't find any spaces, echo statements or anything of the like. I've thrown in a random echo statement to see if my if's else's were being entered correctly, and they are. I definitely get into the else statement with the header(location: blah) code when an incorrect username/password is used... Here's the code I'm looking at. (And there is More HTML under this...) <?php session_start();?> <?php include("passwords.php"); //this statement will be entered if coming from the login.php page. if ($_POST["ac"]=="log"){ //check if submitted username and password exist in $PASSWORD array if ($PASSWORD[$_POST["username"]]==$_POST["password"]){ //set various session variables $_SESSION["username"]=$_POST["username"]; $_SESSION["firstname"]=$FIRSTNAME[$_POST["username"]]; $_SESSION["lastname"]=$LASTNAME[$_POST["username"]]; $_SESSION["email"]=$EMAIL[$_POST["username"]]; } else{ //if username and password do not exist, set session variable for "incorrect username/password" message and redirect to login.php $_SESSION['incorrect'] = "incorrect"; header('Location: login.php'); }; }; // check if user is logged in already when they are coming from a random place. If not, redirect to login.php check_logged(); ?> Any ideas out there why my header('Location: login.php'); line is not working?
  3. I completely hear you. However this method has come down the pipeline, and alas, I'm just the lowly programmer. The bosses are asking for the multiple checkbox type answer. Maybe I was silly in telling them that I could do it...but hey, I kind of enjoy the logic aspect. If I absolutely can't figure it out, then yes, your solution was going to be my fall back. And I do already have that code working. Essentially if I have radio buttons instead of checkboxes, the problem is pretty straight forward. But until I run out of time, I'm going to do my best to do the checkbox method to appease the boss so he doesn't have to rewrite his test.
  4. I guess this problem might be going a different direction anyway...so this might not even matter. But I could still potentially use some help...I'm having a tricky time thinking through this one. Say we have the same question: 1. Select the two (2) main sources of non-introduced atmospheric hazards in a wind turbine hub? SF6 Nitrogen Hydrogen H2S I have a seperate page that simply lists the questions, correct answer etc, and it's included in my page that generates the test. The code question looks like this: //question 1 $question[$i] = 'Select the two (2) <i>main</i> sources of <i>non-introduced</i> atmospheric hazards in a wind turbine hub?'; $answer[$i][1] = 'SF6'; $answer[$i][2] = 'Nitrogen'; $answer[$i][3] = 'Hydrogen'; $answer[$i][4] = 'H2S'; $correct[$i][1] = $answer[$i][2]; //Only edit the number to reflect which selection is the correct answer $correct[$i][2] = $answer[$i][3]; $type[$i] = 'checkbox'; $explanation[$i] = 'All turbine hubs have either a Nitrogen Accumulator or Battery back-up system which must be considered a hazard until proven otherwise by atmospheric testing and visual inspection. '; $i++; //this increments the counter by 1. Do not edit this line, yet make sure this is after each question "block." Now, before, I thought I was making this so that either the user got it all right, or all wrong. Nothing in between. So I figured (and I've changed the code a little since then) that I could just have $correct[$i] = $answer[$i][2].$answer[$i][3] which creates a string called "NitrogenHydrogen" If the user selected any boxes other that Nitrogen and Hydrogen, their string would be different when it compares it to $correct[$i]. (This method has worked tried and true for me with radio buttons. I'm running into the issues with checkboxes) Lately I just found out that this question will actually be worth 4 pts. Each correct state of a checkbox is worth 1 pt. So If they DON'T check SF6, they get a point, another 2 pts are awarded for checking both Nitrogen and Hydrogen, and the last point awarded for NOT checking H2S. That means I have to check every single state of each checkbox and compare it to my $correct[$i] answers. If there are any ideas how to do this I'm all ears. Otherwise I think I just have to think through it and see if can figure this out. I THINK I'm on the right track...
  5. So in response to ginerjm, Yes, I'm looping through the entire POST array because I actually have several questions with checkboxes.... In not exactly HTML terms, it looks like this. Question 1: "Blah blah blah" Answer 1: Has input type=checkbox, name=1 value=answer[1][1] Answer 2: Has input type=checkbox, name=1 value=answer[1][2] Answer 3: Has input type=checkbox, name=1 value=answer[1][3] Question 2: "Blah blah blah" Answer 1: Has input type=checkbox, name=2 value=answer[2][1] Answer 2: Has input type=checkbox, name=2 value=answer[2][2] Answer 3: Has input type=checkbox, name=2 value=answer[2][3] This way I can loop through the questions, and within that loop I can loop through the answers. In response to Psyco, here is what was output when I did the var_dump. array(1) { [1]=> array(2) { [0]=> string(3) "SF6" [1]=> string(3) "H2S" } } (I had SF6 checked, and H2S checked, which was the 1st, and 4th checkbox in that certain grouping of "answers") The reason I have it run through and "assume" a specific value in a specific order is because this is a testing scenario. I essentially have the correct answer in the correct order, and if the user clicks the correct checkboxes, it creates a string that compares with my "correct answer" string. If the two strings match, the user gets points. If the two strings don't match, the user loses points. I'm all ears if there is a better way to do a multiple choice test where the user is allowed to select multiple answers from one group. Here's the actual question that we are dealing with right now, so you're aware... 1. Select the two (2) main sources of non-introduced atmospheric hazards in a wind turbine hub? SF6 Nitrogen Hydrogen H2S (The correct answer is Nitrogen and Hydrogen)
  6. Actually it is in a loop...Sorry, I thought this bit of code was unnessary to include, but here is the entire loop, etc. for($i=1; $i<=$totalquest; $i++){ if(!empty($_POST[$i])){ foreach($_POST[$i] as $check){ $answer .= $check; } echo $answer; if($check!=$correct[$i]){ $WrongAnswers .= "<b>You answered Question $i incorrectly:</b><br>$question[$i]<br>You answered: $answer<br>The correct answer is: $correct[$i]<br>$explanation[$i]<p>"; $score=$score-1; } } }
  7. So I'm kind of new to PHP, and have been having lots of success, but I have no idea why this is occuring. It's probably a super easy answer... I have a form that has checkboxes. Essentially I am echoing out the results of which ever checkboxes the user checks. Here's my code... if(!empty($_POST[$i])){ foreach($_POST[$i] as $check){ $answer .= $check; } echo $answer; And the result that is echoed out says this.. ArraySF6Nitrogen (SF6 is one of the checkboxes that was selected, and Nitrogen is the other checkbox that was selected) I would be incredibly happy if the echoed out result just said SF6Nitrogen My question is why does it say "Array" first?
×
×
  • 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.