插入基于搜索结果的多条记录时出现问题。搜索字段工作正常。但问题是插入不起作用。此外,在我插入记录之前,我必须编辑任何我想要的“等级”字段部分。这是我的代码。
<?php
require_once('../../_includes/initialize.php');
?>
<html><br />
<form action="search.php" method="POST">
<?php
echo "<b><center>Search Results</center></b><br><br>";
if (isset($_POST['search_name'])) {
$search_name = $_POST['search_name'];
if (!empty($search_name)) {
$query="SELECT * FROM students WHERE course like '%".mysql_real_escape_string($search_name)."%'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if (($num) >=1) {
//echo 'Found.';
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$f_name=mysql_result($result,$i,"f_name");
$g=mysql_result($result,$i,"dump");
?>
<input name="id" type="text" value="<?php echo @$id; ?>" size="40" />
<input name="f_name" type="text" value="<?php echo @$f_name; ?>" size="40" />
<input name="a" type="text" value="<?php echo $g; ?>" size="40" />
<br />
<?php
$i++;
}
} else {
echo 'No results found.';
}
}
}
?>
<?php
if (isset($_POST['Submit_Grade'])) {
$query = "INSERT INTO samplestudgrade (id, name, grade) VALUES ('".$_POST["id"]."','".$_POST["f_name"]."','".$_POST["a"]."')";
$query_run = mysql_query($query);
}
?>
<input name="search_name" type="text" value="search..." />
<input type="submit" value="Search"/>
<input type="submit" name="Submit_Grade" value="submit" />
</form>
</html>