1-11$_PHP无法跳转的问题
在表单输入用户名、密码、邮箱之后,点立即注册网页无法访问。而且打开PHP提示Undefined index: username in E:\PHP\software\wamp64\www\about php\12.form.php on line 6
求解决方法
HTML文件:
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="utf-8">
<title>注册页面</title>
</head>
<body>
<h1>注册页面</h1>
<form action="localhost\about php\12.form.php" method="post">
<table border="1" width="70%" cellpadding="0" bacolor="#abcdef" >
<tr>
<td>用户名</td>
<td><input type="text" name="username" placeholder="请输入用户名"/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password" placeholder="请输入密码"></td>
</tr>
<tr>
<td>邮箱</td>
<td><input type="email" name="email" placeholder="请输入合法邮箱"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="立即注册"/></td>
</tr>
</table>
</form>
</body>
</html>
PHP文件:
<?php
header('content-type:text/html;charste=utf-8');
echo $_POST['username'],'<br/>';
echo $_POST['password'],'<br/>';
echo $_POST['email'],'<br/>';
正在回答
您好,1.进入页面报错。原因:程序第一次运行此时用户还没有输入任何内容,因此是接收不到$_POST内容的,所以报错。可以先判断是提交post数据,有数据再输出。
2.网页无法访问。原因:跳转链接错误。按照绝对路径(C:\www)或者相对路径(./fun.php)的方式即可。
可参考:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <!DOCTYPE html> <html dir= "ltr" > <head> <meta charset= "utf-8" > <title>注册页面</title> </head> <body> <h1>注册页面</h1> <form action= "function.php" method= "post" > <table border= "1" width= "70%" cellpadding= "0" bacolor= "#abcdef" > <tr> <td>用户名</td> <td><input type= "text" name= "username" placeholder= "请输入用户名" /></td> </tr> <tr> <td>密码</td> <td><input type= "password" name= "password" placeholder= "请输入密码" ></td> </tr> <tr> <td>邮箱</td> <td><input type= "email" name= "email" placeholder= "请输入合法邮箱" ></td> </tr> <tr> <td colspan= "2" ><input type= "submit" name= "submit" value= "立即注册" /></td> </tr> </table> </form> </body> </html> <?php header( 'content-type:text/html;charste=utf-8' ); if (isset( $_POST [ 'submit' ])){ echo $_POST [ 'username' ], '<br/>' ; echo $_POST [ 'password' ], '<br/>' ; echo $_POST [ 'email' ], '<br/>' ; } |
如果解决了您的问题,请采纳。祝学习愉快!
- 参与学习 人
- 提交作业 626 份
- 解答问题 4928 个
想要学好Web后端开发的中流砥柱语言,本阶段为你轻松铺就扎实的基础,从前端网页布局的搭建到后台PHP开发,助你从零基础到掌握主流开发语言。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧