if statement in php

Reply

Join Date: Jan 2005
Posts: 20
Reputation: scoobie is an unknown quantity at this point 
Solved Threads: 0
scoobie scoobie is offline Offline
Newbie Poster

if statement in php

 
0
  #1
Jan 26th, 2005
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['TimeData']."'>".$row['TimeData']."</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['TimeData']."'>".$row['TimeData']."</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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 193
Reputation: YoungCoder is an unknown quantity at this point 
Solved Threads: 2
YoungCoder's Avatar
YoungCoder YoungCoder is offline Offline
Junior Poster

Re: if statement in php

 
0
  #2
Jan 27th, 2005
I beleive you are looking for something like:

[php]
<?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
}
?>
[/php]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC