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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.