php初学者在线急等如何处理这一入门问题

bolipan 2003-09-28 08:43:15
我现在有两个php页面,第一个是做用户注册的,而第二个是第一个提交之后显示出用户注册时的整个信息清单的,但是总是由于变量说是没有定义的问题,搞的我焦头烂耳的,恳请那位帮我修改一下如何?(我前两天只是提出了问题,问题没有解决,分数却给扣了)我现在把两个页面的代码全部附在下面,希望那位能不能给我在调通了之后告诉我具体的解决办法?谢了!
//---index.php清单如下
<html>
<head>
<title>Index</title>
</head>
<body>
<h2 align="center">User Registration form</h2>
<form name="registration" method="post" action="confirm.php" enctype="mutipart/form-data" >
<table width="400" border="1" align="center" cellpadding="5"
cellspacing="0" bgcolor="#CCCCCC">

<tr>
<td Width="47%">
Full name
</td>
<td colspan="2">
<input type="text" name="name" size="25" maxlength="25">
</td>
</tr>


<tr>
<td Width="47%" height="57">
Address
</td>
<td height="17" colspan="2">
<textarea name="address" cols="26" rows="4"> </textarea>
</td>
</tr>


<tr>
<td Width="47%">
Email
</td>
<td height="2" colspan="2">
<input type="text" name="email" size="25" maxlength="50">
</td>
</tr>


<tr>
<td Width="47%">
Password
</td>
<td height="2">
<input type="password" name="password" size="25" maxlength="15">
</td>
</tr>


<tr>
<td Width="47%">
Confirm Password
</td>
<td height="2">
<input type="password" name="cpassword" size="25" maxlength="15">
</td>
</tr>

<tr>
<td width="47%">
Data of Birth
</td>
<td height="2">
<select name=birth_month>
<option selected value=1>January
<option selected value=2>February
<option selected value=3>March
<option selected value=4>April
<option selected value=5>May
<option selected value=6>June
<option selected value=7>July
<option selected value=8>August
<option selected value=9>September
<option selected value=10>October
<option selected value=11>Novenber
<option selected value=12>December</option>
</select>

<select name=birth_day>
<option selected value=1>01
<option selected value=2>02
<option selected value=3>03
<option selected value=4>04
<option selected value=5>05
<option selected value=6>06
<option selected value=7>07
<option selected value=8>08
<option selected value=9>09
<option selected value=10>10
<option selected value=11>11
<option selected value=12>12
<option selected value=13>13
<option selected value=14>14
<option selected value=15>15
<option selected value=16>16
<option selected value=17>17
<option selected value=18>18
<option selected value=19>19
<option selected value=20>20
<option selected value=21>21
<option selected value=22>22
<option selected value=23>23
<option selected value=24>24
<option selected value=25>25
<option selected value=26>26
<option selected value=27>27
<option selected value=28>28
<option selected value=29>29
<option selected value=30>30
<option selected value=31>31</option>
</select>
<input maxlength=4 name=birth_year size=4>
</td>
</tr>


<tr>
<td Width="47%">
Gender
</td>
<td>
<table border=0>
<tr>
<td height="2" width="26%">
<input type="radio" name="gender" value="Male"> Male </td>
<td height="2" width="27%">
<input type="radio" name="gender" value="Female"> Female </td>
</tr>
</table>
</td>
</tr>

<tr>
<td width="%47">
Please choose topics of interest
</td>
<td height="2">
<table width="100%" border="0">
<tr>
<td>
<input type="checkbox" name="fiction" value="1">
Fiction</td>
<td>
<input type="checkbox" name="horror" value="1">
Horror</td>
<td>
</tr>

<tr>
<td>
<input type="checkbox" name="action" value="1">
Action</td>
<td>
<input type="checkbox" name="comedy" value="1">
Comedy</td>
</tr>
<td>
<tr>
<td>
<input type="checkbox" name="thriller" value="1">
Thriller</td>
</tr>
 
</td>
</tr>
</table>
</td>
</tr>

<tr>
<td width="47%" height="47">
<p align="right">Select hobbies </p>
<p align="right">(Selcect multiple choiced by holding the ctrl key and clicking on them one by one)</p>
</td>
<td height="47">
<p align="center">
<select name="hobbies[]" size="7" multiple>
<option value="Outdoor Sports">Outdoor Sports </option>
<option value="Adventure Sports">Adventure Sports </option>
<option value="Pop Music">Pop Music </option>
<option value="Rock Music">Rock Music </option>
<option value="Aggressive Music">Aggressive Music </option>
<option value="Photography">Photography </option>
</select>
</p>
</td>
</tr>

<tr>
<td align="center" colspan="3">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
下一个confirm.php的清单在楼下。


...全文
65 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hcfyxy 2003-09-28
  • 打赏
  • 举报
回复
php的官方站点http://www.php.net,初学者可以到那里去看各种各样的文档。
gaoxiulan 2003-09-28
  • 打赏
  • 举报
回复
你for循环的第二个条件不对,不应该是count($_POST['hobbies'],而应该是select的size,也就是7,
<?php
//echo count($_POST["hobbies"]);
for($i=0;$i<=6;$i++){
if($_POST["hobbies"][$i]!=""){
?>
<input type="text" name="<?php echo $_POST["hobbies"][$i]?>" value="<?php echo $_POST["hobbies"][$i]?>">
<?
}//if
}//for
?>
试试看!
bolipan 2003-09-28
  • 打赏
  • 举报
回复
问题再现:对于刚才的变量引用问题差不多解决了,但是我在使用那个多选项时:代码如下
<select name="hobbies[]" size="7" multiple>
<option value="Outdoor Sports">Outdoor Sports </option>
<option value="Adventure Sports">Adventure Sports </option>
<option value="Pop Music">Pop Music </option>
<option value="Rock Music">Rock Music </option>
<option value="Aggressive Music">Aggressive Music </option>
<option value="Photography">Photography </option>
</select>
在这里我定义了hobbies【】这个数组,我在confirm.php中引用时好像有问题,代码如下:
for( $i=0;$i < count( $_POST['hobbies'] );$i++ )
{
echo "< input type=hidden name=\"hobbies[ ]\"value\" ".$_POST['hobbies']."\" >\n";
}
其次,在我的多选框中有5项,我若是全部选定的话,就没有问题,若是缺少某一项的话,在confirm中就会给出该变量没有定义的错误信息,请问一下这又是什么原因?
急盼解决。谢谢大家了!
dari 2003-09-28
  • 打赏
  • 举报
回复
to:xuzuning(唠叨)
您好!像我对Web开发毫无基础的情况下,我能不能学php?
刚才你说初学应选择稳定的版本php4.3.1,在哪里下载好?
学php必须有具备哪个条件才能迅速理解,谢谢!
bolipan 2003-09-28
  • 打赏
  • 举报
回复
非常感谢大家,我的问题已经解决了。
xuzuning 2003-09-28
  • 打赏
  • 举报
回复
最好的php编辑器就是"记事本"。
在没有在线帮助的情况下,迫使你认真对待每一行代码。从而使你的水平迅速提高。
初学应选择较稳定的版本php4.3.1就可以了。

不要偷懒而去修改php建议的设置。
出于安全考虑没有几个isp供应商会提供register_globals = On的环境。
在php5中,HTTP_????_VARS也不再存在于全局数组里了。全局数组$GLOBALS中只有$_????变量组。这也是出于安全考虑,可杜绝通过全局数组获取服务器信息的途径。

bolipan 2003-09-28
  • 打赏
  • 举报
回复
"就要到php5时代了,请放弃php4.1.0以前的写法。"
能不能请教一下到什么地方下载最新版本的php,能不能推荐一种好的php编辑器?
maxid 2003-09-28
  • 打赏
  • 举报
回复
补一点。不是所有变量。是FORM提交过来的变量用$_POST[];
可以和上面一样,也可以象下面这样写
$name = $_POST['name'];//php4.10之后支持该用法,同时支持下面的用法
or
$name = $HTTP_POST_VARS['name'];//php4.10之前的用法
hl73 2003-09-28
  • 打赏
  • 举报
回复
在你的php.ini文件中找到 register_globals = 这一行
将其改为 “register_globals = On”
如不想改 在后一个页面对于post方法用$HTTP_POST_VAR,get方法用$HTTP_GET_VARS存取前一个页面提交过来的值。
还有,可以将php.ini文件中error_reporting 段该成以下所显示那样。
; - Show all errors, except for notices
;
error_reporting = E_ALL & ~E_NOTICE
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors except for notices
;
;error_reporting = E_ALL; display all errors, warnings and notices
shuiaaa 2003-09-28
  • 打赏
  • 举报
回复
在php.ini 改成register_globals = On就可以
xuzuning 2003-09-28
  • 打赏
  • 举报
回复
就要到php5时代了,请放弃php4.1.0以前的写法。
所有表单提交的变量都使用$_POST数组引用,如
<input type="radio" name="gender" value="Female">
php程序中引用表单变量gender使用$_POST['gender']而不是用$gender。
当然你可以$gender = $_POST['gender'];然后再用$gender
maxid 2003-09-28
  • 打赏
  • 举报
回复
你的所变量用$_POST['']来代替。例如$name用$_POST['name']代替、$email用$_POST['email']代替......
你还是看旧的资料来学PHP吧,建议你到www.php.net去下载最新的学习资料。
www.phpe.com也是一个好站点
希望我们一起进步。分数不是问题
bolipan 2003-09-28
  • 打赏
  • 举报
回复
我是一个程序设计初学者,对于csdn中我的分数实在是很少,我希望我能得到真正的解决问题的具体一点的答案。感谢大家了!
bolipan 2003-09-28
  • 打赏
  • 举报
回复
//----confirm清单如下:
<html>
<head>
<title>Index</title>
</head>
<body>
<h2 align="center">User Registration Confirmation Page</h2>
<form name="registration" method="post" action="output.php" enctype="mutipart/form-data">
<table width="300" border="1" align="center" cellpadding="5" cellspacing="0" bgcolor="#CCCCCC">
<tr>
<td width="47%" align="right"> <B>Full Name </B> </td>
<td>
<?php
if( empty( $name ) )
{
die("Invalid name");
}
else
{
echo $name;
}
?>
</td>
</tr>

<tr>
<td width="47%" height="57" align="right"> <B> Address </B></td>
<td height="57">
<?php
if(empty($address))
{
die("No address submitted");
}
elseif( ( strlen( $address ) < 5 ) || ( strlen( $address ) > 50 ) )
{
die("Invalid address");
}
else
{
echo $address;
}
?>
</td>
</tr>

<tr>
<td width="47%" align="right"> <B>email</B> </td>
<td height="2">
<?php
if( empty( $email ) )
{
die( " No email address submitted" );
}
elseif( ( strlen( $email) <5 ) || ( strlen( $email) > 50 ) )
{
die( "Invalid email address,email address too long or too short." );
}
elseif( !ereg( "@",$email ) )
{
die( "Invalid email address,no @ symbol found" );
}
else
{
echo $email;
}
?>
</td>
</tr>

<tr>
<td width="47%" align="right"> <B>password </B> </td>
<td height="2">
<?php
if( empty( $password ) || empty( $cpassword ) )
{
die( "No password submitted" );
}
elseif( ( ( strlen( $password ) < 5 ) || ( strlen( $password ) > 15 ) ) )
{
die( "Invalid password length address" );
}
elseif( !( strlen( $password ) == strlen( $cpassword ) ) )
{
die( "Password do not match!" );
}
elseif( ! ($password == $cpassword ) )
{
die( "Password do not match!" );
}
else
{
for( $i = 0;$i < strlen( $password );$i++ )
{
echo "*";
}
}
?>
</td>
</tr>

<tr>
<td width="47%" align="right" > <B>DoB </B> </td>
<td height="2">
<?php
if( empty( $birth_month ) || empty( $birth_day ) || empty( $birth_year ) )
{
die( "Date of birth not submitted or incomplete." );
}
switch( $birth_month )
{
case 1:print "January";break;
case 2:print "Febuary";break;
case 3:print "March";break;
case 4:print "April";break;
case 5:print "May";break;
case 6:print "June";break;
case 7:print "July";break;
case 8:print "August";break;
case 9:print "September";break;
case 10:print "October";break;
case 11:print "November";break;
case 12:print "December";break;
default:die( "Invalid birth month !!" );
}
if( ( $birth_day < 1 ) || ( $birth_day > 31 ) )
{
die( "Invalid date!" );
}
else
{
echo $birth_day," ";
}
if( ( $birth_year < 1900 ) || ( $birth_year > 2000 ) )
{
die( "Invalid birth year");
}
else
{
echo $birth_year;
}
?>
</td>
</tr>

<tr>
<td width="47%" align="right" >
Gender
</td>
<td height="2" width="26%" >
<?php
if( empty( $gender ) )
{
die( "Gender not specified" );
}
elseif( !( ( $gender == "Male" ) || ( $gender == "Female" ) ) )
{
die( "Invalid value for gender" );
}
else
{
echo $gender;
}
?>
</td>
</tr>

<tr>
<td width="47%" align="right" > <B> Topics of interests</B>
</td>
<td height="2" colspan="2">
<table width="100%" border="0">
<tr>
<td>
<?php
if( $fiction )
{
echo "fiction <br>";
}
if( $horror )
{
echo "horror <br>";
}
if( $action )
{
echo "action <br>";
}
if( $comedy )
{
echo "comedy <br>";
}
if( $thrillers )
{
echo "thrillers <br>";
}
?>
</td>
</tr>
</table>
</td>
</tr>

<tr>
<td width="47%" height="47" align="right"> <B> Select hobbies </B>
</td>
<td colspan="2" height="47">
<p align="center">
<?php
for( $i=0;$i < count( $hobbies );$i++ )
{
echo $hobbies[$i] ."<br>";
}
?>
</td>
</tr>

<tr>
<td colspan="3">
<FORM Name=confirm action="output.php">
<?php
echo "< input type=hidden name=\"name\"value\" ".$name."\" >\n";
echo "< input type=hidden name=\"address\"value\" ".$address."\" >\n";
echo "< input type=hidden name=\"email\"value\" ".$email."\" >\n";
echo "< input type=hidden name=\"birth_month\"value\" ".$birth_month."\" >\n";
echo "< input type=hidden name=\"birth_day\"value\" ".$birth_day."\" >\n";
echo "< input type=hidden name=\"birth_year\"value\" ".$birth_year."\" >\n";
echo "< input type=hidden name=\"interests\"value\" ".$interests."\" >\n";
for( $i=0;$i < count( $hobbies );$i++ )
{
echo "< input type=hidden name=\"hobbies[ ]\"value\" ".$hobbies[ $i ]."\" >\n";
}
if( $fiction )
{
echo "< input type=hidden name=\"fiction\"value\" ".$fiction."\" >\n";
}
if( $action )
{
echo "< input type=hidden name=\"action\"value\" ".$action."\" >\n";
}
if( $horror )
{
echo "< input type=hidden name=\"horror\"value\" ".$horror."\" >\n";
}
if( $comedy )
{
echo "< input type=hidden name=\"comedy\"value\" ".$comedy."\" >\n";
}
if( $thrillers )
{
echo "< input type=hidden name=\"thrillers\"value\" ".$thrillers."\" >\n";
}
?>
<center> <input="submit" name="Submit" value="Confirm >>">
</center>
</form>
</td>
</tr>
</table>
</form>
</body>
</html>

麻烦各位了!

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧