Jump to content

store drop down value


diasansley

Recommended Posts

how do i get a drop down value and store it in a another table

as of now i am getting the value from one table showing it on drop down now once that is selected i need to insert it into another table.

<html>
<?php

	mysql_connect('localhost','root','') or die('Could not connect to mysql ' . mysql_error());
        mysql_select_db("dbtest") or die(mysql_error());

	if(isset($_POST['submit'])) { //$name=$_POST['val'];
		$id = $_POST['select'];
		          $id=$row['name'];
		?>
				<input type="text" name="name2" value="<?php echo $row['name'] ?>"><br />
       <?php
      $query = "INSERT INTO sub (`sub`) values('" . $id . "')";
            $result = mysql_query($query);
                 
		if($query) {                       
			echo "query executed";         
		}

    
    } 
    ?>

<form id="name" action="<?php $_POST['SERVER_SELF'] ?>" method="POST" >
	<input type="text" name="name1"><br />
	<select name="select" id="select">
	<?php
		$query = "SELECT name,id FROM main"; 
            $result = mysql_query($query);
            
		if($query) {  
                while($row = mysql_fetch_array($result)) {
				$options .= '<option value="' . $row['name'] . '">' . $row['name'] . '</option>';
        //  $out .= "<option value=\" . $row['name'] . \" >' . $row['name'] . '</option>";    
			}
		}

		echo $options;
	?>

	</select>

	<input type="submit" name="submit1">
</form>

</html>

Thanks the above seem to work.

Link to comment
https://forums.phpfreaks.com/topic/226650-store-drop-down-value/
Share on other sites

When the form is submitted, the php script that handles the processing of that form will grab the value set in the drop down, and then use it in a query that will insert the value into the 'other' table.

 

You obviously need to code that, but that's the general idea of what to do.

 

Denno

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.