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.

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

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路