html - php 获取表单数据
怪我咯
怪我咯 2017-04-10 16:38:41
[PHP讨论组]

我有两个php问件
其中
add.php:

姓名
性别
年龄
班级
 

action.php:

switch($_GET['action']){
    case "add":
        $name = $_POST['name'];
        $sex = $_POST['sex'];
        $arge = $_POST['arge'];
        $classId = $_POST['classId'];
        $sql = "insert into students VALUES (NULL ,'{$name}','{$sex}','{$arge}','{$classId}')";
        $rw = $pdo->exec($sql);
        if($rw>0){
            echo "";
        }else{
            echo "";
        }
    break;
}

提交数据时为什么会报如下错误:

Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 16

Notice: Undefined index: sex in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 17

Notice: Undefined index: arge in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 18

Notice: Undefined index: classId in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 19

name sex arge classId 不是都有么 为何还时 未定义??

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(3)
PHP中文网
  • -问题没发现,倒是发现第一次看到case可以这样用的,就不怕出错么?

PHP中文网

form 没有设置encoding 属性。

encoding='application/x-www-form-urlencoded'

PHP中文网

这样吧。你先var_dump($_POST);

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

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