繁体   English   中英

根据用户输入从数据库中检索数据

[英]Retriving data from database based on user input

我是php的新手,并且正在学习基础知识,我设计了一种具有动态下拉菜单的表单,该菜单中的选项直接从Access DB中填充。 用户选择一个选项后,与该选项有关的信息将显示在操作页面中,但不能正常工作。 我将代码运行了好几天,但似乎并没有弄错什么。 注释的代码似乎是我的问题根源。 这是代码

<html>
<head>
<title>Menu</title>
</head>
<body>
<?php
// This would be the value passed from the previous php page
$option =$_POST['myDropdown'];

// for testing purposes
print("$option");

// print image of the menu item or dish
print <<< HERE

<p>
<img src = "DishesPictures/Dish-$option.png" border="1" bordercolor="black"
       alt = "die: $option" />

</p>
HERE;

$conn = new COM("ADODB.Connection") or die("Cannot start ADO"); 


 $connString= "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=e:\\ectserver\\naljalidi\\Database\\Menu.mdb";
    //creates the connection object and define the connection string

// for testing purposes
print("$connString");

$rs=$conn->Execute("SELECT ItemID,ItemDesc,Price FROM Menu WHERE ItemID=$option;");
//if (!$rs->EOF)
//{
  // $ItemID=$rs->Fields("ItemID");
  // $ItemDesc=$rs->Fields("ItemDesc");
  // print("$ItemID");
  // print("$ItemDesc");
//}


$rs->Close();


?>
</body>

</html>

我的数据库信息:数据库名称:菜单表:仅一个,名为菜单字段:ItemID(PK,AutoNumber),ItemDesc(Text),Price(Currancy)

有什么帮助吗? 谢谢

添加代码:

$conn->SetFetchMode(ADODB_FETCH_ASSOC);  
$rs=$conn->Execute("SELECT ItemID,ItemDesc,Price FROM Menu WHERE ItemID=$option;");
if (!$rs) {  
print $conn->ErrorMsg();  
 } else
{
 $ItemID=$rs->Fields['ItemID'];
 $ItemDesc=$rs->Fields['ItemDesc'];
 print("$ItemID");
 print("$ItemDesc");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM