Your problem is here:
$result = mysql_query("SELECT supplier FROM supplier");
while($row = mysql_fetch_array($result))
{
/*echo '<form action="">';*/
echo "<select name='supplier'>";
echo "<option value = '$row[supplier]'>""</option>";
echo "</select>";
You're creating the drop down box (the Select) inside of the mysql data loop. As @Hitesh has explained. You need to create this outside of the loop and only echo out the data results within. For example:
$result = mysql_query("SELECT supplier FROM supplier");
echo "<select name='supplier'>";
while($row = mysql_fetch_array($result))
{
echo "<option value=".$row['supplier'].">".$row['supplier']."</option>";
}
echo "</select>";
This will output your drop down box, with all your supplier names as the value and the displayed text options.
If you attempted to do the following:
$result = mysql_query("SELECT supplier FROM supplier");
while($row = mysql_fetch_array($result))
{
/*echo '<form action="">';*/
echo "<select name='supplier'>";
echo "<option value = '$row[supplier]'>""</option>";
echo "</select>";
}
You would just end up with as many drop down boxes as you had suppliers in your database. This is because you're creating a new Select box for each record found.
Also, without specifying the second $row['supplier'] between the option tags, you'd just end up with a blank (empty) drop down box.
Hope this helps.
$con = mysql_connect("localhost","user","pass") or die('Could not connect: ' . mysql_error()); mysql_select_db("rtgs", $con) or die('Could not select database');Then put this code in a seperate file (connect.php) and include this at the top of every page you need to connect to your database from withinclude('connect.php');