| | |
if statement in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2005
Posts: 20
Reputation:
Solved Threads: 0
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
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
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]
[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]
Class Info:
Warrior Priest | Bright Wizard |Witch Hunter | Rune Priest |Engineer | Hammerer |Ironbreaker | Black Orc |Orc Choppa | Goblin Shaman |Squig Herder | Chosen |Magus | Zealot | Marauder
Warrior Priest | Bright Wizard |Witch Hunter | Rune Priest |Engineer | Hammerer |Ironbreaker | Black Orc |Orc Choppa | Goblin Shaman |Squig Herder | Chosen |Magus | Zealot | Marauder
![]() |
Similar Threads
- php within echo statement / hide element (JavaScript / DHTML / AJAX)
- Switch statement in PHP (PHP)
- SQL Statement in PHP (PHP)
- PHP If Statement question (PHP)
- how do i use php?id and what are they? (PHP)
- php wont submit data into the database (PHP)
Other Threads in the PHP Forum
- Previous Thread: Seeting up and calling variables stored in sessions
- Next Thread: Php-nuke and MySQL trouble
| Thread Tools | Search this Thread |
# 5.2.10 action address apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher destroy display dissertation domain dynamic echo echo$_get[x]changingitintovariable... email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image images include insert ip javascript joomla legislation limit link load login mail masterthesis menu mlm multiple mysql mysqlquery oop open paypal pdf persist php popup problem query radio random record recursion remote script search server sessions sms sockets source space sql syntax system table tutorial update upload url validator variable video web youtube





