本例是从一本参考书上摘下来的,但本人调试后,没有成功。书内容如下:
使用list()函数遍历数组
例:下面通过具体的实例讲解list()和each()函数的综合应用,获取存储在数组中的用户登陆信息。
代码如下:
........................................
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>应用list()函数遍历数组</title>
</head><body>
<form name="form1" method="post">
<table width="323" border="1" cellpadding="1" cellspacing="1" bordercolor="#66CC33" bgcolor="#FFFFFF">
<tr>
<td width="118" height="24" align="right" bgcolor="#CCFF33">用户名:</td>
<td width="192" height="24" bgcolor="#CCFF33"><input name="user" type="text" class="inputcss" id="user" size="24"></td>
</tr>
<tr>
<td height="24" align="right" bgcolor="#CCFF33">密 码:</td>
<td height="24" bgcolor="#CCFF33"><input name="pwd" type="password" class="inputcss" id="pwd" size="24"></td>
</tr>
<tr align="center" bgcolor="#CCFF33">
<td height="24" colspan="2"><input name="submit" type="submit" value="登录"></td>
</tr>
</table>
</form>
<?php
//输出用户登录信息
while(list($name,$value)=each($_POST)){
if($name!="submit"){
echo "$name=$value<br>";
}
}
?>
</body>
</html>
......................................
打开IE浏览器,有一个登陆框显示出来,输入用户名和密码,单击“登陆”的按钮,应该会有显示的啊,但是网页就看不见了,不知为什么,请PHP高手讲解!
使用list()函数遍历数组
例:下面通过具体的实例讲解list()和each()函数的综合应用,获取存储在数组中的用户登陆信息。
代码如下:
........................................
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>应用list()函数遍历数组</title>
</head><body>
<form name="form1" method="post">
<table width="323" border="1" cellpadding="1" cellspacing="1" bordercolor="#66CC33" bgcolor="#FFFFFF">
<tr>
<td width="118" height="24" align="right" bgcolor="#CCFF33">用户名:</td>
<td width="192" height="24" bgcolor="#CCFF33"><input name="user" type="text" class="inputcss" id="user" size="24"></td>
</tr>
<tr>
<td height="24" align="right" bgcolor="#CCFF33">密 码:</td>
<td height="24" bgcolor="#CCFF33"><input name="pwd" type="password" class="inputcss" id="pwd" size="24"></td>
</tr>
<tr align="center" bgcolor="#CCFF33">
<td height="24" colspan="2"><input name="submit" type="submit" value="登录"></td>
</tr>
</table>
</form>
<?php
//输出用户登录信息
while(list($name,$value)=each($_POST)){
if($name!="submit"){
echo "$name=$value<br>";
}
}
?>
</body>
</html>
......................................
打开IE浏览器,有一个登陆框显示出来,输入用户名和密码,单击“登陆”的按钮,应该会有显示的啊,但是网页就看不见了,不知为什么,请PHP高手讲解!
<?php
//输出用户登录信息
print_r( $_POST );
while(list($name,$value)=each($_POST)){
if($name!="submit"){
echo "$name=$value <br>";
}
}
?>
<form name="form1" method="post" action="?">
沒有寫action,不知道是不是這個原因,你加上:action=''