SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast jabroni76's Avatar
    Join Date
    Dec 2003
    Location
    Gawgia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ¡Problem! and one question!

    alright, I inserted a point system into my site and have a minor problem...

    in answer1.php I have this:

    Code:
    <html>
    <body>
    <?
    
    $var = $HTTP_POST_VARS["test"];
    
    echo "<p><b><i>Your answer was:</b></i>";
    echo "<br><br>";
    echo $var;
    echo "<br><br>";
    echo "<hr>";
    echo "<br>";
    echo "<b><i>The correct answer was:</b></i>";
    echo "<br><br>";
    echo "A part of a line that starts at a point and extends infinetly in one direction.</p>";
    
    $total = 0;
    ?>
    <img src="images/ray.gif">
    <form action="continue.php" method="post">
    <table align="center" border=0>
      <tr bgcolor=#cccccc>
    	<td align="center" width=250>Did you answer this question 	correctly?</td>
      </tr>
      <tr>
    	<td align="center"><select name="answer">
    		<option value = "yes"> Yes
    	 	<option value = "no"> No
    	    </select>
    	</td>
      </tr>
      <tr>
    	<td align="center"><input type=submit value="Let's go on!"></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    in continue.php (where a form forwards you to), I have:

    Code:
    <?php session_start(); ?>
    <html>
    <body>
    
     <?php
     switch ( $_POST['answer'] ) {
     	case 'yes':
     	    echo( 'Congrats' );
     	    break;
     	case 'no':
     	    echo( 'Drats' );
     	    break;
     }
     ?>
     <p>You have 
     <?php
     $_SESSION['points'] = ( isset($_POST['total']) ) ? $_POST['total'] : $_SESSION['points'];
     
     if ( $_POST['answer'] == 'yes' )
     	echo( $_SESSION['points']++ );
     else
     	echo( $_SESSION['points'] = 0 );
    
     if ( $points == 1 )
    	echo( ' point!' );
     else
        	echo( ' points!' );
    	
     ?>
    
     </p>
    
    <?php
      $sites = array("problem2.php", "problem3.php", "problem4.php", "problem5.php");
      $array_elements = count($sites);
      $array_elements_total = $array_elements - 1;
      $random_num = mt_rand(0, $array_elements_total);
      $website_url = $sites[$random_num];  
      print("<a href=\"$website_url\">Link</a>");
    
    ?>
    
     
     </body>
     </html>
    My problem: If I click yes on answer1.php, I get an output of "you have points" when it should be, "you have 1 point". If i hit refresh, I will get what I am supposed to. Why is it like this? I hope this makes sense.

    My question: Is it possible to have two arrays. One with all of my sites in it. THe other would be an array which will fill up once the user clicks "yes" on the answer1.php. So... if you click yes, you should not be directed to that page again.

    thanks in advance for any help!

  2. #2
    SitePoint Addict RapidGaming's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My question: Is it possible to have two arrays. One with all of my sites in it. THe other would be an array which will fill up once the user clicks "yes" on the answer1.php. So... if you click yes, you should not be directed to that page again.
    A cookie could be used here.

  3. #3
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Trickiness of the ++ operator? I think that echo evaluates and outputs $_SESSION['points'] before adding 1 because this is postfix operator...evaluates then addes 1.
    Erh

  4. #4
    SitePoint Enthusiast jabroni76's Avatar
    Join Date
    Dec 2003
    Location
    Gawgia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahh. okay. thanks Mandibal. I changed

    PHP Code:
    echo( $_SESSION['points']++ ); 
    to

    PHP Code:
    echo( ++$_SESSION['points'] ); 
    I don't understand what your saying about the arrays!

    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •