php select表单提交未定义 表单selectphp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果这是全部代码,$_POST['username']和$_POST['passwd']也会报错。 print_r($_POST);看一下post的数据有哪些 其他代码我打了省略号全部代码太多了我试过改成$role =“teacher”;结果就正常。应该是$role = $_POST['role'];取不到表单中的值,但我不知道怎么改。也试过把name值换一个也不行 你在第一行打印一下print_r($_POST);看看有没有role这一项 Array ( [username] => student [passwd] => 123456 )没有select中的值 我的select写错了吗? 页面有js处理么,是不是被js影响了。print_r($_POST); 就知道提交了哪些 没有jsArray ( [username] => student [passwd] => 123456 )没有 role 。。 Array ( [username] => student [passwd] => 123456 )没有select中的值 我的select写错了吗?你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀 Array ( [username] => student [passwd] => 123456 )没有select中的值 我的select写错了吗?你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突? Array ( [username] => student [passwd] => 123456 )没有select中的值 我的select写错了吗?你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?name名相同?你怎么没贴出来 Array ( [username] => student [passwd] => 123456 )没有select中的值 我的select写错了吗?你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?name名相同?你怎么没贴出来。。全贴出来index2.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>登陆模块</title></head> <fieldset> <legend>loading</legend> <form method="post" action="lib\ChkLogin.php"> <table> <tr> <td>username:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>password:</td> <td><input type="password" name="passwd" /></td> </tr> <tr><td>your role:</td> <td> <select name="role"> <option value="student">student</option> <option value="teacher">teacher</option> </select> </td> </tr> <tr> <td><input type="submit" value="ok" /></td> <td><input type="reset" value="no" /></td> </tr> </table> </form> </fieldset><body></body></html>ChkLogin.php<?php$username = $_POST['username'];$passwd = $_POST['passwd'];$role = $_POST['role'];print_r($_POST);if($username==""||$passwd==""){ echo "<script>"; echo "alert(\"用户名或密码不能为空!\");"; echo "location.href=\"../index2.php\";"; echo "</script>"; }else{ include("dbhelper.php"); if($role=="teacher"){ $helper = new dbhelper(); if($helper ->open()){ $row = mysql_fetch_array(mysql_query("select * from teacher where username='$username'")); } $helper ->close(); if($row["password"]==$passwd){ header("location:../teacher.php"); } else{ echo "<script>"; echo "alert(\"用户名或密码错误!\");"; echo "location.href=\"../index2.php\";"; echo "</script>"; } } else if($role=="student"){ $helper = new dbhelper(); if($helper ->open()){ $row = mysql_fetch_array(mysql_query("select * from student where username='$username'")); } $helper ->close(); if($row["passwd"]==$passwd){ header("location:../student.php"); } else{ echo "<script>"; echo "alert(\"用户名或密码错误!\");"; echo "location.href=\"../index2.php\";"; echo "</script>"; } } }?> 我只是把 <form method="post" action="lib\ChkLogin.php">改成<form method="post" action="lib/ChkLogin.php">也就是斜线改一下,我这里可以传过去 第5行的print_r($_POST); 没有role? 其实我很想知道LZ你如果没有role,那为什么第四行的$role = $_POST['role'];不报错。。或者你先把php页面和html页面放到一起,别让action查找路径试试 html 代码为什么不写在body里面 警告,页面已过期,这个大家是怎么解决的? 问一个查询结果的数组排序处理 PHP下载系统如何防止下载工具多线程下载重复扣点? 为什么在本机上smarty可用,到了liunx系统下smarty里的display就不能用 了 求一段更行数据库数据的代码(根据ID) 另外我写了一个方法大家帮我看看 mysql 如何修改数据库文件默认路径window系统的. 求 解chunked编码过的字符串函数。 ADODB数据类,能否连接SQlite数据库 各位DX帮忙,多谢 php如何读取命令行输入! 用GD库的问题 thinkphp留言板如何写?
看一下post的数据有哪些
我试过改成$role =“teacher”;结果就正常。
应该是$role = $_POST['role'];取不到表单中的值,但我不知道怎么改。
也试过把name值换一个也不行
没有select中的值
我的select写错了吗?
print_r($_POST); 就知道提交了哪些
Array ( [username] => student [passwd] => 123456 )
没有 role 。。
没有select中的值
我的select写错了吗?
你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
没有select中的值
我的select写错了吗?
你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?
没有select中的值
我的select写错了吗?
你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?
name名相同?你怎么没贴出来
没有select中的值
我的select写错了吗?
你确定action里面的地址没错吗,是提交到ChkLogin.php,我把你的代码复制下来,能接收到呀
那是因为我建了结构目录。在<form>中<select>之前有个<input>,是不是因为<input>的username的值和role的值一样的会冲突?
name名相同?你怎么没贴出来
。。全贴出来
index2.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登陆模块</title>
</head>
<fieldset>
<legend>loading</legend>
<form method="post" action="lib\ChkLogin.php">
<table>
<tr>
<td>username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" name="passwd" /></td>
</tr>
<tr><td>your role:</td>
<td>
<select name="role">
<option value="student">student</option>
<option value="teacher">teacher</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="ok" /></td>
<td><input type="reset" value="no" /></td>
</tr>
</table>
</form>
</fieldset>
<body>
</body>
</html>ChkLogin.php
<?php
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$role = $_POST['role'];
print_r($_POST);
if($username==""||$passwd==""){
echo "<script>";
echo "alert(\"用户名或密码不能为空!\");";
echo "location.href=\"../index2.php\";";
echo "</script>";
}
else{
include("dbhelper.php");
if($role=="teacher"){
$helper = new dbhelper();
if($helper ->open()){
$row = mysql_fetch_array(mysql_query("select * from teacher where username='$username'"));
}
$helper ->close();
if($row["password"]==$passwd){
header("location:../teacher.php");
}
else{
echo "<script>";
echo "alert(\"用户名或密码错误!\");";
echo "location.href=\"../index2.php\";";
echo "</script>";
}
}
else if($role=="student"){
$helper = new dbhelper();
if($helper ->open()){
$row = mysql_fetch_array(mysql_query("select * from student where username='$username'"));
}
$helper ->close();
if($row["passwd"]==$passwd){
header("location:../student.php");
}
else{
echo "<script>";
echo "alert(\"用户名或密码错误!\");";
echo "location.href=\"../index2.php\";";
echo "</script>";
}
}
}
?>
或者你先把php页面和html页面放到一起,别让action查找路径试试