I'm making some dynamic drop down boxes for a site that get their contents from a database, i belive i have the correct code to do this

<?php
echo "Product Code";
$sql = "SELECT DISTINCT Product_Code FROM product_supplier";
$result = mysql_query($sql, $odbc) or die("could not run");



echo"<select name = Product_Code>";
echo"<option value = All >All</option>";

while($row=mysql_fetch_object($result))
{
echo "<option value = '".$row->Product_Code."'>$row->Product_Code</option>";

}

echo"</select>";
echo "</p>";
?>

Whenever i try to run it in the webpage it brings this error

Warning: mysql_query() expects parameter 2 to be resource, null given in F:\xampp\xampp\htdocs\G4U\G4U\purchase.php on line 30

Can anybody see whats wrong with it???

There's something wrong with the $odbc link identifier. Please show the section where you have defined that.

There's something wrong with the $odbc link identifier. Please show the section where you have defined that.

$odbc? wheres that go???

Here is the page code if it help?

<html>
<head>
<title>Gardens 4 U |  Purchase</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#container #mainContent h1 {
	text-align: center;
}
#container #mainContent form table {
	text-align: right;
	font-size: 12px;
}
-->
</style>
</head>

<body class="thrColFixHdr">

<div id="container">
  <div id="header">
    <h1>&nbsp;</h1>
  </div>
  <div id="mainContent">
<h2>Purchase</h2>
<p>&nbsp;</p>
<p>
  <?php
echo "Product Code";
$sql = "SELECT DISTINCT Product_Code FROM product_supplier";
$result = mysql_query($sql, $odbc) or die("could not run");
echo"<select name = Product_Code>";
while($row=mysql_fetch_object($result))
{
echo "<option value = '".$row->Product_Code."'>$row->Product_Code</option>";

}

echo"</select>";
echo "</p>";
?>
<p>&nbsp;</p>
  </div>
  <div id="footer">
    <p>Privacy | Access | Contact</p>
  </div>
</div>
</body>
</html>

just solved it myself, forgot to connet

/facepalm

New problem though, i now need another list box (thingy) with the products supplier in, but i want it to show the suppliers related to that product only.

Any Ideas How?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.