登录  /  注册
在下php表单验证时 出现 Notice: Undefined index: email in F:\apache\Apache24\htdocs\chap01\form1.php on line 21要怎么办。
W
W 2017-11-17 12:32:48
[PHP讨论组]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>表单验证</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="description" content="" />

<meta name="keywords" content="" />

<script type="text/javascript">


</script>


<style type="text/css">

</style>

</head>

    <body>

    <?php

$name = $email =$gender =$comment = $website ="";


if($_SERVER["REQUEST_METHOD"] == "POST"){

    $name = test_input($_POST["name"]);

    $email = test_input($_POST["email"]);

    $website = test_input($_POST["website"]);

    $comment = test_input($_POST["comment"]);

    $gender = test_input($_POST["gender"]);

}

function test_input($data){

    $data = trim($data);

    $data = stripslashes($data);

    $data = htmlspecialchars($data);

    return $data;

}

?>


<h2> php 验证实列</h2>

<form method="post" action ="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

姓名:<input type="text" name ="name">

<br><br>

电邮:<input type="text" email ="email">

<br><br>

网址:<input type="text" website ="website">

<br><br>

评论:<input type="text" comment = "comment">

<br><br>

性别:

<input type="radio" name ="gender" vlaue ="female">女性

<input type="radio" name ="gender" vlaue ="male">男性

<br><br>

<input type="submit" name="submit" value = "提交">

</form>


<?php

echo "<h2>您的输入为:</h2>";

echo "<br>";

echo $name;

echo "<br>";

echo $email;

echo "<br>";

echo $website;

echo "<br>";

echo $comment;

echo "<br>";

echo $gender;

?>

    </body>

</html>


W
W

愿能多结交志同道合的基友!哈哈哈。。。。。

全部回复(2)
phpcn_u61612

QQ截图20171117142103.png

QQ截图20171117142130.png

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>表单验证</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<?php
$name = $email = $gender =$comment = $website ="";
if($_SERVER["REQUEST_METHOD"] == "POST"){
    $name = test_input($_POST["name"]);
    $email = test_input($_POST["email"]);
    $website = test_input($_POST["website"]);
    $comment = test_input($_POST["comment"]);
    $gender = test_input($_POST["gender"]);
}
function test_input($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
<h2> php 验证实列</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
姓名:<input type="text" name="name">
<br><br>
电邮:<input type="text" name="email">
<br><br>
网址:<input type="text" name="website">
<br><br>
评论:<input type="text" name="comment">
<br><br>
性别:
<input type="radio" name="gender" vlaue ="female">女性
<input type="radio" name="gender" vlaue ="male">男性
<br><br>
<input type="submit" name="submit" value = "提交">
</form>
<?php
echo "<h2>您的输入为:</h2>";
echo "<br>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
?>
</body>
</html>


热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号