1 $answer=Array();2 $answer[0]= ' 0 ';3 for($i= 1;$i<=$QUESTION _count;$i++){ 4 $answer[$i]=$_post[(string)$i];//18th Line of error5 if($i<= ($CHOOSE _count+$FILL _count)){6 if($answer[$i]==$right _answer[$i-1]){7 $grade=$grade+5;8 $right _count++;9}Else{Ten $wrong _count++; One } A } -}// for
Apart, first report the wrong part of the code!
After running the following prompt:
notice:undefined offset:1 in E:\wwwroot\center.php on line 18
notice:undefined Offset:2 in E:\wwwroot\center.php on line 18
notice:undefined Offset:3 in E:\wwwroot\center.php on line 18
notice:undefined Offset:4 in E:\wwwroot\center.php on line 18
notice:undefined Offset:5 in E:\wwwroot\center.php on line 18
Reason:
First appeared on the internet also checked, a lot of people are let you go to modify php.ini, let it not show, I think this is not self-deception (although feasible simple rough), why not to look for reasons to change their own code.
Cause of error: The front-end HTML submission form when the individual input blank to cause error, so that $_post[(string) $i] assigned to the array and to use the array is an undefined phenomenon (in short, the back end does not determine whether the front-end table items are filled, such as radio not selected).
Solve:
First on the code
1 $answer=Array();2 $answer[0]= ' 0 ';3 for($i= 1;$i<=$QUESTION _count;$i++){ 4 if(!isset($_post[(string)$i])){//first decide whether to define5 $answer[$i]= ' 0 ';//manual Assignment if undefined6}Else{//defines the direct assignment of the value7 $answer[$i]=$_post[(string)$i];8 if($i<= ($CHOOSE _count+$FILL _count)){ 9 if($answer[$i]==$right _answer[$i-1]){Ten $grade=$grade+5; One $right _count++; A}Else{ - $wrong _count++; - } the } - } -}// for
Check whether the value from the front end is undefined with isset (), and if it is not defined, it is manually assigned (the case of my Web application needs to be assigned manually), and you can feedback it to the user in a different way.
PHP get form and use array store crazy hint notice:undefined offset