View Full Version : dynamic drop downs

07-13-2012, 03:53 AM
Dear All,

I have new in PHP & MySql. I need two dynamic drop down box which will popolate the data from database. After watching your tutorial I am able to solve my problem. But now I need another option. I want this dropdown box value into my another database. I am able to do this bt problem is, instead of name it is storing the correspondent integer value. another issue is when I select one drop down box value its auto saves the first box value in database without giving chance to select the second drop down box. I am submitting the code below for your to see where I make mistake.



$program = $_POST['program'];

if ($program){

$query = sprintf("SELECT * FROM program_name where program_name='$program'");
$result = @mysql_query($query);
$rowModel = mysql_fetch_array($result);

<title>Untitled Document</title>


<form id="form1" name="form1" method="post" action="insert_ac.php" >

<select name="program" onChange="document.forms[0].submit()">
<option value="">Select Make</option>
<option value="1" <?php if(!(strcmp(1, $program))){echo "selected";}?>>Team A</option>
<option value="2" <?php if(!(strcmp(2, $program))){echo "selected";}?>>Team B</option>

<select name="Item_Code">
<option value="">Select Model</option>
<?php do { ?>
<option value="<?php echo $rowModel['program']; ?>"><?php echo $rowModel['Item_Code']; ?></option>
<?php }while ($rowModel = mysql_fetch_array($result)); ?>
<input type="submit" name="Submit" value="Submit Your Order Information...">




$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="date"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form



// Insert data into mysql
$sql="INSERT INTO $tbl_name(program, Item_Code)VALUES('$program', '$Item_Code')";

// if successfully insert data into database, displays message "Successful".
echo "Successful";
echo "<BR>";
echo "<a href='index.php'>Back to main page</a>";

else {
echo "ERROR";

// close connection

thanks to all in advance.