How to insert dynamic dropdown selected value in other table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

How to insert dynamic dropdown selected value in other table

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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' "; ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

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

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post by social_experiment »

Yeah, correct.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

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

Post by pavanesh2009 »

Thanks social_experiment" & lshaw!! :D
social_experiment wrote:Yeah, correct.
Post Reply