Hi,

i was wondering if anyone can help me. i have an a form that has two options A and B in it. when the user choses an option and clicks submit a php script is executed.

what i want to do is if the user selects option A then it executes a query and if they click option b then they execute a different query.

Here is some sample code:

Form

<td>
<tr>
<td>
<input type="radio" name=TimeDataFrm value="Buy Data" checked>Buy Data
</td>
</tr>
<tr>
<td>
<select name=DataOptionFrm>
<?php
$qry = "SELECT TimeData FROM Chrgtbl WHERE TimeData Like '%m%'";
$result = mysql_query($qry);
while($row = mysql_fetch_array($result))
echo "<option value = '".$row."'>".$row."</option>";
?>
</select>
</td>
</tr>
</td>

<td>
<tr>
<td>
<br>
<br>
<input type="radio" name=TimeDataFrm value="Buy Time">Buy Time
</td>
</tr>
<tr>
<td>
<select name=TimeOptionFrm>
<?php
$qry = "SELECT TimeData FROM Chrgtbl WHERE TimeData Like '%Mi%'";
$result = mysql_query($qry);
while($row = mysql_fetch_assoc($result))
echo "<option value = '".$row."'>".$row."</option>";
?>
</select>
</td>
</tr>
</td>


php script with queries

if ($TimeOptionFrm && $TimeOptionFrm != '')
{
$insert = "insert into tickettbl (TimeData) values ('$TimeOptionFrm')";
$result = mysql_query($insert) or die(mysql_error());
if ($result)
echo "Time";
}
else
{
$insert = "insert into tickettbl (TimeData) values ('$DataOptionFrm')";
$result = mysql_query($insert) or die(mysql_error());
if ($result)
echo "Data";
}


can anybody help me please

scoobie

I beleive you are looking for something like:

<?php
if{$_POST["TimeDataFrm"] == "Buy Data"){
	// Add code you wish to add here
} else if ($_POST["TimeDataFrm"] == "Buy Time"){
	// Add code you wish to add here
} else {
	// Neither have been selected, add error message code here
}
?>
This article has been dead for over six months. Start a new discussion instead.