1

I am new to php, and I am learning the basics, I designed a form that has a dynamic drop down menu where the options are populated directly from my Access DB. After the user choose an option, the information related to that option would be displayed in a operate page, but that does not work properly. I run over my code for days and I do not seem to get what is wrong. The commented code seems to be my source of problem. this is the code

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

My DB information: Database Name: Menu Table: only one , named Menu Field: ItemID(PK, AutoNumber), ItemDesc(Text), Price(Currancy)

Any help? Thank you

2
  • 1
    You're using html inside php tags as it is. You should either echo html or close php tag before using html tags Commented Jul 5, 2012 at 6:00
  • 1
    I am using print insted of echo, and I would like to know what html tags you are referring too,if it is the img one then I removed it and tested my code but still it is the same problem. Thanx anyway Commented Jul 5, 2012 at 6:08

1 Answer 1

2

Add the code:

$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");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.