其中
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 16notice: undefined index: sex in /applications/xampp/xamppfiles/htdocs/studentsmanager/action.php on line 17notice: undefined index: arge in /applications/xampp/xamppfiles/htdocs/studentsmanager/action.php on line 18notice: undefined index: classid in /applications/xampp/xamppfiles/htdocs/studentsmanager/action.php on line 19
name sex arge classid 不是都有么 为何还时 未定义??
回复内容: 我有两个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 16notice: undefined index: sex in /applications/xampp/xamppfiles/htdocs/studentsmanager/action.php on line 17notice: undefined index: arge in /applications/xampp/xamppfiles/htdocs/studentsmanager/action.php on line 18notice: undefined index: classid in /applications/xampp/xamppfiles/htdocs/studentsmanager/action.php on line 19
name sex arge classid 不是都有么 为何还时 未定义??
你后面的错误是你 单独 在地址栏中打开 你的 action.php?action=add的时候显示的吧?
当你单独在浏览器中直接打开你的action.php?action=add的时候, 它是以get的方式请求的, 而且不会有post的数据过去, 所以你这个时候, 去取$_post['xxx'] php 会有一个 notice 的提示(在允许显示的情况下).
正常从你的 add.php 点按钮(有填写页数据的情况下), 是没有报你说的那个问题的.
-问题没发现,倒是发现第一次看到case可以这样用的,就不怕出错么?
form 没有设置encoding 属性。
encoding='application/x-www-form-urlencoded'
这样吧。你先var_dump($_post);
