<select>数据传递的问题
inquire.html
<html>
<head>
<title>inquire the classroom</title>
</head>
<body>
<h1>CRMS - Inquire the classroom</h1>
<form action="inquire_classroom.php" method="post">
<table border="0">
<tr>
<td>Classroom ID</td>
<td>
<select name="lesson_id">
<option value ="1">1</option>
<option value ="2">2</option>
<option value ="3">3</option>
<option value ="4">4</option>
<option value ="5">5</option>
<option value ="6">6</option>
<option value ="7">7</option>
<option value ="8">8</option>
<option value ="9">9</option>
<option value ="10">10</option>
<option value ="11">11</option>
<option value ="12">12</option>
<option value ="13">13</option>
<option value ="14">14</option>
<option value ="15">15</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
</form>
</body>
</html>
inquire_classroom.php
<html>
<head>
<title>inquire the classroom</title>
</head>
<body>
<h1>CRMS - Inquire the classroom</h1>
<?php
// create short variable names
$lesson_id=$_POST['lesson_id'];
$con = mysql_connect("localhost","root","");
//通过服务器locahost建立连接,用户名为root,无密码
if (!$con)
{
die('Could not connect: ' . mysql_error());
}//如果不成功,显示错误
mysql_select_db("crms", $con);//选择数据库
if (!mysql_select_db("crms", $con)) die(mysql_error());
$search_lesson_id = "SELECT * FROM use2 WHERE lesson_id = '{$lesson_id}'";
$result = mysql_query($search_lesson_id,$con);
if (!$result)
{
die("The lesson does not exist.");
}
while($row = mysql_fetch_array($result))
{
echo $row['Cno'];
echo $row['CID'];
echo "<br />";
}
mysql_close($con);
?>
下拉框选择了一个值提交后,出现
Notice: Undefined index: lesson_id in D:\xampp\htdocs\inquire_classroom.php on line 9
D301001 的错误。但是这里<select name="lesson_id">我不是已经定义了吗?
------解决方案--------------------
$lesson_id=$_POST['lesson_id']; 这样其实是OK的。
改一下php.ini的报错级别:
error_reporting = E_ALL & ~E_NOTICE
改后重启apache。
------解决方案--------------------notice并不是error,不影响结果。
想不出现notice,修改下php.ini中的错误提示级别就行