嗨,我正在为我的学位项目建立一个粗略的原型,上周我有点卡住了。基本上我有一个测试人员系统来记录反病毒软件的测试结果。我已经使用父表中的记录填充了一个下拉列表,现在我想捕获用户选择的值和用户ID,并将其输入到链接表中以记录这一点。但我只想捕获该测试的主键testID,而不是测试的名称,这就是我被困住的地方。如果有人有任何想法,这将帮助我这么多。
继承第一页的代码
<?php
//Template for all pages
$pagename="Select File Associations";
session_start();
include ("mysqli_test.php");
// css style sheet for template
echo "<link rel=stylesheet type=text/css href=stylesheet.css>";
// displays name in window tab
echo "<title>".$pagename."</title>";
// use header file
include("header.html");
// display the current date and time
echo date ('l d F Y H:i:s');
echo "<p></p>";
// display page name on the page
echo "<h2>".$pagename."</h2>";
$testsql = "SELECT testID, testName from tests";
$testresult = mysql_query($testsql);
echo "<td>Select Test:</td>";
echo "<select name= testName>";
while ($row = mysql_fetch_array($testresult))
{
echo "<option value=\"". $row['testID']."\">". $row['testName']. "</option>";
}
echo "</select>";
echo "<form method=post action= confirm_selection2.php>";
echo "<tr><td><input type=submit value='Submit'></td>";
echo "<td><input type=reset value='clear'></td></tr>";
// use footer file
include("footer.html");
?>
然后是表单处理页面confirm_selections.php
<?php
//Template for all pages
$pagename="confirm_selection";
session_start();
include ("mysqli_test.php");
// css style sheet for template
echo "<link rel=stylesheet type=text/css href=stylesheet.css>";
// displays name in window tab
echo "<title>".$pagename."</title>";
// use header file
include("header.html");
// display the current date and time
echo date ('l d F Y H:i:s');
echo "<p></p>";
// display page name on the page
echo "<h2>".$pagename."</h2>";
// retrieve POST data from the user selected test
$testselection=$_POST['testName'];
// check if the selections were made
if(isset($testselection)){
$instestSQL = "INSERT INTO test_performance SET
testID='$testselection'
testerID='$_SESSION['testID']);
$exeintestSQL=mysql_query($instestSQL) OR die(mysql_error());
}
// use footer file
include("footer.html");
?>
答案 0 :(得分:0)
select元素位于表单之外,将其更改为:
echo "<form method=post action= confirm_selection2.php>";
echo "<select name= testName>";
while ($row = mysql_fetch_array($testresult))
{
echo "<option value=\"". $row['testID']."\">". $row['testName']. "</option>";
}
echo "</select>";
echo "<tr><td><input type=submit value='Submit'></td>";
echo "<td><input type=reset value='clear'></td></tr>";
echo "</form>";
所有表单元素都应放在<form></form>
元素内。