douwen9534 2013-03-04 19:00
浏览 25
已采纳

从下拉菜单中捕获用户所选值的数据库ID

Hi I'm currently building a rough prototype for my degree project and I have got a bit stuck for the last week. Basically I have a system for testers to record test results from anti-virus software. I've populated a dropdown with records from a parent table and now I would like to capture the user selected value and the users id and input this into a link table to record this. But I only wanted to capture the primary key testID for that test not the name of the test, this is where I'm stuck. If anyone has any ideas this would help me out so much.

Heres the code for the first page

<?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");
?>

Then the form handling page 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");

?>
  • 写回答

1条回答 默认 最新

  • douhua1760 2013-03-04 19:05
    关注

    The select element is outside your form, change it to:

    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>";
    

    All form elements should be placed inside <form></form> element.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制