Forums

PHP

This topic is locked

updating a table if a specific option is selected

Posted 25 Mar 2008 09:26:40
1
has voted
25 Mar 2008 09:26:40 Topex omondi posted:
Hi,
I have been trying to develope a code for updating a table if a specific option is selected from a dropdown list the following is a select option code.
<select name="x_visittype" id="x_visittype"><? echo $visittype;?>
<option>Select</option>
<option id="x_visittype">ADM</option>
<option id="x_visittype">NE</option>
<option id="x_visittype"><?php echo($opt);?></option>
<option id="x_visittype">AC</option>
<option id="x_visittype">CO</option>
</select>
The logics for the update statement are as follows;
if ($opt="AN"
{
$sql="UPDATE samps SET visit1='1' where demographic_id='$demoid'";
$res = mysql_query($sql) or die(mysql_error());
}
elseif($opt="V2"
{
$sql="UPDATE samps SET visit2='1' where demographic_id='$demoid'";
$res = mysql_query($sql) or die(mysql_error());
}
elseif($opt="V3"
{
$sql="UPDATE samps SET visit3='1' where demographic_id='$demoid'";
$res = mysql_query($sql) or die(mysql_error());
}
elseif($opt='V4')
{

$sql="UPDATE samps SET visit1='',visit2='',visit3='',visit4='' where demographic_id='$demoid'";
$res = mysql_query($sql) or die(mysql_error());
}
How do i intergrate the update statements to ensure that samps table is updated iff $opt is selected.
Currently the table updated if any of the options is selected.
Thanxs,
Julie

julie

Reply to this topic