0

I have this (simple) code. I want to retrieve a random value from each array and then ask the user to tell me what the answer is when they've been multiplied.

The user arrives at this page after declaring their name on the previous page and their name arrives in a SESSION variable.

Nothing happens when this page is arrived at!! Nothing. Just a blank page...

I was doing something before without arrays (just using random numbers) and it worked fine. Now I have arrays... problems.

Here is the code:

<?php session_start(); ?>

<html>
<head>
    <?php 

    $first=array(2,4,8,10);
    $second=array(2,4,8,10);

    $b=rand(0,3);
    $c=rand(0,3);

    $f=$first['$b'];
    $s=$second=['$c'];

    $d=$f*$s;
    $score=$_SESSION["score"];
    $name=$_SESSION["name"];
    ?>


</head>
<body>

    <?php

    echo $name." your score so far=".$score;
    echo "<br>";
    ?>




    <?php echo"Write the answer";?>
    <br>
    <?php echo $f."x".$s."=";?>

<form method= "post" action="submit.php">
    <input type="number" name=a value="0">
    <input type="hidden" name=b value=<?php echo $f;?>>
    <input type="hidden" name=c value=<?php echo $s;?>>
    <input type="submit" name=submit value="Go!">


</form>

stilts77
  • 191
  • 3
  • 14
  • 1
    `$f=$first['$b'];` Don't use any quotes, right now it's just the string `$b` – Rizier123 May 09 '15 at 11:38
  • 1
    $f=$first[$b]; $s=$second=[$c]; Use like this. quotes are not required at all. – Alive to die - Anant May 09 '15 at 11:38
  • Hello Both - Thank you for looking at this... the biggest problem was the fact that I had a rogue = in this line: $s=$second=['$c']; Obviously it should have been: $s=$second['$c']; I need to find a way that my editor tells me I've done this!! – stilts77 May 09 '15 at 12:54

0 Answers0