943,940 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7313
  • PHP RSS
Jan 26th, 2005
0

if statement in php

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scoobie is offline Offline
20 posts
since Jan 2005
Jan 27th, 2005
0

Re: if statement in php

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]
Reputation Points: 13
Solved Threads: 2
Junior Poster
YoungCoder is offline Offline
193 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Seeting up and calling variables stored in sessions
Next Thread in PHP Forum Timeline: Php-nuke and MySQL trouble





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC