Nil Jay
Nil Jay

Reputation: 35

How to make 1 scored points earned show up?

I am trying to create a quiz with score points. The following program creates text files of data of the answers i try to compare the values but it says error everytime but When i execute the code it says zero points earned

<?php
$d = 'joe frazier';
$f = 'muhammad ali';
if( isset( $_POST['name100'] ) ) {
    $username2 = $_POST['name'];
    $password2 = $_POST['name1'];

    $file1 = fopen($username2, "w+" );
    $file2 = fopen($password2, "w+" );
    $s2  = $username2 = $_POST['name'] ;
    $d2   = $password2 = $_POST['name1'] ;
    fputs( $file1, $s2 ) or die ( "Data not written" );
    fputs( $file2, $d2 ) or die ( "Data not written" );


    if($s2=="Floyd Mayweather"){echo "1 points earned";}else{echo "0 points earned";}
}

else{
    echo
    "<center>\
<form method = 'post'>
<br>Which athlete has won 50 fights and lost zero fights?<br>
<input type='text' name = 'name'><br>
<br>Who is the fastest man alive?<br>
<input type='text'  name = 'name1'><br>

<br>Who won two fights  out of  three in the fight muhammad ali vs joe frazier fight?   
<br><input type='radio' name='name2' > $f<br>
<br><input type='radio' name='name2' > $d <br>
<br><input type='submit'  name = 'name100'><br>
</form>  </center>\ "
     ;

}
//expected output : 1 points earned 

// output right now : 0 points earned
?>

Upvotes: 0

Views: 25

Answers (1)

InvictusMKS
InvictusMKS

Reputation: 411

I was able to get the expected result by copying and pasting your code and doing a copy and paste for the expected value.

I would see what $s2 is being set to and test by copy & pasting Floyd Mayweather in the text box. It might be a simple typo.

If that doesn't work try doing a trim() and or a strcasecmp() on the variable.

Upvotes: 1

Related Questions