我正在尝试创建带有分数的测验。 以下程序创建答案数据的文本文件 我尝试比较这些值,但每次都显示错误,但 当我执行代码时,它说赚了零分
<?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
?>
答案 0 :(得分:1)
我能够通过复制和粘贴代码并复制并粘贴期望值来获得预期结果。
我会看到$ s2设置为什么,并通过在文本框中复制和粘贴 Floyd Mayweather 进行测试。这可能是一个简单的错字。
如果这样不起作用,请尝试对变量执行trim()和或strcasecmp()。