Page 1 of 1

How to insert dynamic dropdown selected value in other table

Posted: Thu Feb 04, 2010 7:06 am
by pavanesh2009
Hi Everyone!!

Can anyone please suggest me how I can insert selected dropdown value(once user selects any of the value) in some other table.for this I am passing a dropdown value to another page, I tried it by using $_POST but error comes here is my query:

$query = "SELECT species_id FROM Species_master WHERE $_POST['species_name']";

is this the correct way of doing this.

Thanks in advance!!

Also I am passing "species_name " Because my form look like this:
<form action="tracktrees.php" method="POST" name="species" id= "species">
<input type="hidden" id = "species_scientific" name ="species_name" value ="">
<tr>

<td width="150">species_scientific_name</td>

<td width="150"><select name="species_scientific_name" onChange="getspecies_primary_common_name(this.value);getfamily(this.value);">

<?php
$sql = mysql_query("SELECT species_id,species_scientific_name FROM Species_master ");

while($row = mysql_fetch_array($sql))
{
$data2 .= "<option value='{$row['species_id']}'>{$row['species_scientific_name']}</option>";
}
echo $data2;
?>

</select></td>

</tr>

Please suggest how I can insert selected dropdown value in some other table.

Re: How to insert dynamic dropdown selected value in other table

Posted: Thu Feb 04, 2010 9:39 am
by social_experiment
If you have a drop down menu you can access the information (value) like you would an array.

Code: Select all

<?php if (is_array($_POST['species_name'])) { foreach ($_POST['species_name'] as $species_name);  } ?>
Your query would then look like :

Code: Select all

<?php $query = "SELECT species_id FROM Species_master WHERE '$species_name' "; ?>

Re: How to insert dynamic dropdown selected value in other table

Posted: Thu Feb 04, 2010 9:50 am
by lshaw

Code: Select all

 
$query = "SELECT species_id FROM Species_master WHERE $_POST['species_name']";
 
The where clause must have a column name ie.

Code: Select all

 
$query = "SELECT species_id FROM Species_master WHERE species_name=$_POST['species_name']";
 
Someone correct me if I am wrong :D

Lewis

Re: How to insert dynamic dropdown selected value in other table

Posted: Thu Feb 04, 2010 10:07 am
by social_experiment
Yeah, correct.

Re: How to insert dynamic dropdown selected value in other table

Posted: Tue Feb 16, 2010 11:10 pm
by pavanesh2009
Thanks social_experiment" & lshaw!! :D
social_experiment wrote:Yeah, correct.