-1

i have one combo box in one html page another page i want to call the database.in the database select the customer name these names are diaplayed in combo box respectively.please the code for me.

Dinesh
  • 29
  • 1
  • 7
  • 4
    We won't do it for you, show us what you have got so far and someone might be able to help you. – mdm Mar 16 '11 at 08:19

1 Answers1

1

First off, Don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.


<?php 
$db_name = "db";
$connection = mysql_connect('localhost','root','') or die(mysql_error());
$db = mysql_select_db($db_name,$connection) or die(mysql_error());
$sql = "SELECT customer_name,id from customers ORDER BY customer_name desc";
$result = mysql_query($sql,$db) or die(mysql_error());
if(mysql_num_rows($result)>=1){
    $form = '<form method="POST" action="">
    <p>Customer name:<select size="1" name="customer">';
    while ($row = mysql_fetch_array($result)) {
        $form .='<option value="'.$row['id'].'">'.ucwords($row['customer_name']).'</option>';
    }
    $form .=' </select></p><p><input type="submit" value="Submit"></p></form>';
}
echo $form;
?>
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106