Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 28th, 2005, 08:17 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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




Similar Threads
Thread Thread Starter Forum Replies Last Post
how many items can mysql store? yulin11 MySQL 1 December 6th, 2007 11:58 AM
Populate Select Menu from MySQL Database joviyach PHP Databases 4 June 24th, 2006 09:38 PM
How I store & retrieve List/Menu Mysql/PHP gsedrak1 PHP Databases 3 September 15th, 2005 08:49 PM
Store Checkbox values in MySQL Database jkilgore Beginning PHP 1 July 7th, 2005 03:43 PM
Two data items from a populated dropdown menu bear1138 Dreamweaver (all versions) 1 August 13th, 2003 09:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.