logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 07-13-2012, 04:53 AM   #1
Ripon
 
Join Date: Jul 2012
Posts: 1
Default

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.

dropdown.php
PHP Code:
<?php 
require_once("config.php"); 

$program    =    $_POST['program'];


if (
$program){

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

}
?>
<head>
<title>Untitled Document</title>
</head>

<body>

<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>
 

  <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));  ?>
  </select>
  <input type="submit" name="Submit" value="Submit Your Order Information...">
</form>

</body>
</html>


insert_ac.php

<?php

$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

$program=$_POST['program'];

$Item_Code=$_POST['Item_Code'];

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

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

else {
echo 
"ERROR";
}
?>

<?php
// close connection
mysql_close();
?>
thanks to all in advance.

Ripon

Last edited by edbr; 07-13-2012 at 05:15 AM..
Ripon is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:28 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com