提交文件如下:
9list2 Tell Us About Your Baby!
指向的文件如下:
$errors=array();
if(empty($name))
$errors[]="You didn't enter your baby's name.";
if(!isset($sex))
$errors[]="You didn't enter your baby's sex.";
if(!isset($rating))
$errors[]="Please rate your baby.";
if(is_array($drinks))
{
$ndrinks=count($drinks);
print $ndrinks;
var_dump($drinks);
for($i=0;$i<$ndrinks;$i++)
{
if($drinks[$i]="rum_punch")
{
$errors[]="You can't feed rum punch to a baby!";
}
}
}
$nerrors=count($errors);
if($nerrors>0)
{
print "
Error There were problems with your form. Please go back to the previous page and correct the following errors:
";
for($i=0;$i<$nerrors;$i++)
print "- ".$errors[$i]."
\n";
print "
\n\n";
exit;
}
/*
$need_list="";
$drink_list="";
if(is_array($needs))
$need_list=join(", ",$needs);
if(is_array($drinks))
$drink_list=join(", ",$drinks);
$name = str_replace("\t"," ",$name);
$sex = str_replace("\t"," ",$sex);
$rating = str_replace("\t"," ",$rating);
$drink_list = str_replace("\t"," ",$drink_list);
$datafile="\\tmp\\baby_info_datafile.txt";
$fp=fopen($datafile,"a");
if($fp==false)
die("Can't open data file \"$datafile\".\n");
fwrite($fp,$name."\t".$sex."\t".$rating."\t".$need_list."\t".$drink_list."\n");
fclose($fp);
*/
?>
Thank you!Thanks for taking our survey!
当没有选择多项选单的任何无素时~~~弹出如下信息:
Notice: Undefined variable: drinks in C:\Program Files\Apache Group\Apache2\htdocs\baby-survey-1-handler.php on line 11
当任意选择一个或多个无素时~~~用来记录错误的数组$errors都会所被选择的无素记录为错误,即出现:
You can't feed rum punch to a baby!
可我的代码却时:
if(is_array($drinks))
{
$ndrinks=count($drinks);
print $ndrinks;
var_dump($drinks);
for($i=0;$i<$ndrinks;$i++)
{
if($drinks[$i]="rum_punch")
{
$errors[]="You can't feed rum punch to a baby!";
}
}
}
我实在看不出那里出错了~~~
请大家帮忙