Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!, i have the code below to populate the combobox from mysql table(location) values, can anyone help me how insert the selected option into mysql database table(customer)using html/php post method....

PHP
//php function to populate combobox


 function location(){

   $database="da_name"
   mysql_connect ("localhost", "root", "pasword");
   @mysql_select_db($database) or die("Unable to select database");
   $query="SELECT state,location FROM location"

   $result = mysql_query ($query);
   echo '<select name="id" value=" ">';
   // printing the list box select command

   while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
   echo "<option value=$nt[location]>$nt[location]</option>";
   /* Option values are added by looping through the array */
   }
   }
   echo "</select>";
// Closing of list box
   ?>


** now I have table (customer with fields -->name, location, contact) please anyone can help how to insert the selected option along with the name & contact fields

*** please help me with the code for data.php & insert.php to complete the application
Posted
Updated 23-Feb-12 0:20am

1 solution

try this one.

PHP
// Form a query to populate the combo-box
$queryitem = "SELECT state, location FROM location"

// Successful query?
if($result = mysql_query($queryitem))  {

  // If there are results returned, prepare combo-box
  if($success = mysql_num_rows($result) > 0) {
    // Start combo-box
    echo "<select name='item'>n";
    echo "<option>-- Select Item --</option>";

    // For each item in the results...
    while ($row = mysql_fetch_array($result))
      // Add a new option to the combo-box
      echo "<option value='$row[location]'>$row[location]</option>n";

    // End the combo-box
    echo "</select>n";


Best Regards,
@iamsupergrasya
 
Share this answer
 
Comments
ramen79 26-Feb-12 1:01am    
thanks for the code, i shall try and come back

regards

ramen
graciax8 29-Feb-12 21:10pm    
Ok. If you have other questions just comment and if this is helpful, mark as answer.

Best Regards,
@iamsupergrasya

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900