php代码从两个表单中获取值并将其插入表中

时间:2015-12-13 17:50:13

标签: php

我在一个页面上有两个表单。第一个根据小组记录学生的名字。第二种形式用于单独输入标记。现在我想插入他们的标记,但未能这样做。请帮我解决这个问题。我的代码是:

$faculty = null; //declare vars

$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
mysql_select_db('Sims', $link) or die("cannot select DB");

 if(isset($_POST["faculty"]))
  {
      $faculty = $_POST["faculty"]; 
   }
   ?>
 <script language="JavaScript">
 function autoSubmit()
 {
  var formObject = document.forms['theForm'];
  formObject.submit();
  }
</script>
 <form name="theForm" method="post">
<select name="faculty" onChange="autoSubmit();">
    <option value="null"></option>
    <option value="computer" <?php if($faculty == 'computer') echo "    selected"; ?>>Computer</option>
    <option value="commerce" <?php if($faculty == 'commerce') echo " selected"; ?>>Commerce</option>
</select>
 <br><br>
<?php
if($faculty =='computer')
{
echo "<select name=\"name\">";
$sql =  mysql_query("SELECT name FROM std_reg where faculty= 'computer' ") or die(mysql_error()); 
while($row = mysql_fetch_array($sql)){
echo "<option>".$row[name]."</option>";}
echo "</select>";
}

if($faculty =='commerce')
{
echo "<select name=\"name\">";
$sql =  mysql_query("SELECT name FROM std_reg where faculty= 'commerce' ") or die(mysql_error());
while($row = mysql_fetch_array($sql)){
echo "<option>".$row[name]."</option>";}
echo "</select>";
}
?>
<br><br>
</form>
<form method="post">
math <input type="text" name="urdu" />
science <input type="text" name="science" />
social <input type="text" name="social" />

<a href="insertmarks.php">submit</a>
</form>

0 个答案:

没有答案