Php 基于用户输入从数据库检索数据
我是php新手,正在学习基础知识,我设计了一个表单,它有一个动态下拉菜单,选项直接从Access DB填充。用户选择一个选项后,与该选项相关的信息将显示在操作页面中,但该页面无法正常工作。我把我的代码运行了好几天,似乎没有发现什么地方出了问题。注释过的代码似乎是我问题的根源。 这是密码Php 基于用户输入从数据库检索数据,php,ms-access,Php,Ms Access,我是php新手,正在学习基础知识,我设计了一个表单,它有一个动态下拉菜单,选项直接从Access DB填充。用户选择一个选项后,与该选项相关的信息将显示在操作页面中,但该页面无法正常工作。我把我的代码运行了好几天,似乎没有发现什么地方出了问题。注释过的代码似乎是我问题的根源。 这是密码 <html> <head> <title>Menu</title> </head> <body> <?php // This woul
<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(主键、自动编号)、ItemDesc(文本)、Price(当前)
有什么帮助吗?谢谢添加代码:
$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");
}
您正在php标记中使用html。在使用html标记之前,您应该回显html或关闭php标记。我使用的是print而不是echo,我也想知道您指的是什么html标记,如果是img标记,那么我将其删除并测试了代码,但仍然是相同的问题。反正是Thanx