0

我有两页,一页通过 POST 将值传递给另一页。这些值不会显示在选择操作的第二页上。输入文本框传递它们的值。我已经包含了下面的两个页面

第一页:

mysql_connect("localhost","root","") or die("Unable to connect");
    mysql_select_db("testsite");

$sql = "SELECT state FROM states";
$result = mysql_query($sql);

$sqldegrees = "SELECT degree FROM degrees";
$resultdegrees = mysql_query($sqldegrees);

$sqlschools = "SELECT school FROM schools";
$resultschools = mysql_query($sqlschools);


echo "<html>";
echo "<head>";
echo "<link rel='stylesheet' type='text/css' href='styles.css'/>";
echo "</head>";
echo "<body>";
echo "<h3>Education</h3>";
echo "<form method='post' action='educationhistoryinsert.php'>";
echo "<table border='3' width='280'>";
echo "<tr><td>State:</td><td>";
echo "<select state='state'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['state'] ."'>" . $row['state'] ."</option>";}
echo "</select>";
echo "</td></tr>";
echo "<tr><td>School:</td><td>";
echo "<select school='school'>";
while ($row = mysql_fetch_array($resultschools)) {
echo "<option value='" . $row['school'] ."'>" . $row['school'] ."</option>";}
echo "</select>";
echo "</td></tr>";
echo "<tr><td>Degree:</td><td>";
echo "<select degree='degrees'>";
while ($row = mysql_fetch_array($resultdegrees)) {
echo "<option value='" . $row['degree'] ."'>" . $row['degree'] ."</option>";}
echo "</select>";
echo "</td></tr>";
echo "<tr><td>Subject:</td><td><input type='text' name='subject' maxlength='20'/></td>      
</tr>";
echo "</table>";
echo "<table border='1'>";
echo "<tr>";
echo "<td width='5'>Month:</td><td><input  style='width: 30px;' type='number'     
name='month' maxlength='1'/></td>";
echo "<td width='5'>Year:</td><td><input  style='width: 50px;' type='number'      
name='year' maxlength='5'/></td>";
echo "<td width='5'>GPA:</td><td><input  style='width: 30px;' type='number' name='gpa'    
maxlength='5'/></td>";
echo "</tr>";
echo "</table>";
echo "<input type='submit' value='Save'>";
echo "</form>";
echo "</body>";
echo "</html>";
?>

=======-------------------------------- 'educationhistoryinsert.php'

<?php
$degree = $_POST['degree'];
$subject = $_REQUEST['subject'];

echo $degree."<br/>";
?>
4

3 回答 3

2

您需要更改您的选择名称 -

echo "<select state='state'>";
echo "<select school='school'>";
echo "<select degree='degrees'>";

echo "<select name='state'>";
echo "<select name='school'>";
echo "<select name='degrees'>";

$degree = $_POST['degree'];

缺少sdegrees

$degree = $_POST['degrees'];
于 2013-08-08T04:20:09.023 回答
0

由于您使用的是 HTML(不是 XML),因此您需要提供默认标签属性,例如name=""* 或使用 data-XYZ

其中XYZ是您的自定义属性。

所以为了得到正确的结果只需替换

  • state='state'name='state'
  • school='school'name ='school'
  • degree='degrees'name ='degrees'

那么它应该工作

于 2013-08-08T04:35:54.883 回答
0

name选择框,如

echo "<select name='degree'>";
echo "<select name='school'>";

然后你可以通过POSTlike得到它们

$degree = $_POST['degree'];
$school = $_POST['school'];
于 2013-08-08T04:20:45.677 回答