p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP Databases (http://p2p.wrox.com/forumdisplay.php?f=97)
-   -   Store Items from dropdown menu in mysql database (http://p2p.wrox.com/showthread.php?t=28694)

scoobie April 28th, 2005 08:17 AM

Store Items from dropdown menu in mysql database
 
Hi,
I was wondering if someone could help me. i have a form where the user is given two menus each with four options the user can choose from. when the user selects from one of the menus and clicks enter it runs a insert.php script that executes an insert query. if the user chooses from the data menu i want it to input the data info in the mysql db table or if they select from the time menu i want it to input the time info into the table.

this code gives the user thier menu options:

//data menu
<input type = "radio" name = "DataFrm" value = "Data">Data

<select name = "DataOptionFrm">
<?php
$qry = "SELECT TimeData, Cost, Description FROM Chrgtbl WHERE TimeData Like '%MB%'";

$result = mysql_query($qry);
while($row = mysql_fetch_array($result))
echo '<option value = "'.$row['TimeData'].'">'.$row['TimeData'].' || € '.$row['Cost'].' || '.$row['Description'].'</option>';
?>
</select>

//time menu
<input type = "radio" name = "TimeFrm" value = "Time">Time

<select name = "TimeOptionFrm">
<?php
$qry = "SELECT TimeData, Cost, Description FROM Chrgtbl WHERE TimeData Like '%MB%'";

$result = mysql_query($qry);
while($row = mysql_fetch_array($result))
echo '<option value = "'.$row['TimeData'].'">'.$row['TimeData'].' || € '.$row['Cost'].' || '.$row['Description'].'</option>';
?>
</select>


i have used the following code to insert the choice into the database but can't get it to work:
if ($DataOptionFrm)
{
$qry = "select ChrgID from chrgtbl where chrgtbl.TimeData = '$DataOptionFrm'";
$result = mysql_query($qry) or die(mysql_error());
$row = mysql_fetch_object($result);

$insert = "insert into tickettbl (AccID, ChrgID, TicketNo, TimeData, RecDate)values ('$TTAccID', '$row->ChrgID', '$Random', '$DataOptionFrm', '$TodaysDate')";

$result = mysql_query($insert) or die(mysql_error());

}
else
{
$qry = "select ChrgID from chrgtbl where chrgtbl.TimeData = '$TimeOptionFrm'";
$result = mysql_query($qry) or die(mysql_error());
$row = mysql_fetch_object($result);

$insert = "insert into tickettbl (AccID, ChrgID, TicketNo, TimeData, RecDate)values ('$TTAccID', '$row->ChrgID', '$Random', '$TimeOptionFrm', '$TodaysDate')";

$result = mysql_query($insert) or die(mysql_error());
}

it enters the right details if i select from the data menu i.e. if i choose 5MB it enters in ID 1. however if i choose any of the four options from the time menu it enters ID 1 which is data and not ID 5,6,7,8. None of the Time options gets entered even if selected. it just keeps entering the 1st Data menu option even if i choose from the Time menu

Can anyone help, i'm really stuck.

Thanks,

scoobie




All times are GMT -4. The time now is 09:07 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.