PDA

View Full Version : Using Combo boxes in forms


Beeky
10-26-2010, 04:31 PM
I am tying myself up in knots a bit here. I have a page where the user can add a new record to the database by filling in the form. So far so good. The initial part of the page calls the current records and shows them in a table thus:

//connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //select a database to work with $selected = mysql_select_db("eachfrie_Events",$dbhandle) or die("Could not select eachfrie_Events"); // query db and loop through rows example /// query db and loop through rows example //$field2 = $_POST['even $field4 = $_POST['eventlocation']; $field5 = $_POST['eventtype']; $field6 = $_POST['eventstatus']; $field7 = $_POST['eventdate']; $field8 = $_POST['starttime']; $field9 = $_POST['endtime']; $field10 = $_POST['coordinator']; $field11 = $_POST['comments']; $field12 = $_POST['fundraised']; $field13 = $_POST['financialyear']; if($field3){ mysql_query("INSERT INTO tblEvents(eventname,eventlocation,eventtype,events tatus,eventdate,starttime,endtime,coordinator,comm ents,fundsraised,financialyear)VALUES('$field3','$ field4','$field5','$field6','$field7','$field8','$ field9','$field10','$field11','$field12','$field13 ')"); /// query db and loop through rows example } /// query db and loop through rows example $query = mysql_query("SELECT * FROM tblEvents ORDER BY eventid;"); //$table = "<table border=\"1\">\n"; $table = "<table border=\"1\" cellspacing=\"10\" body bgcolor=\"#AABBCC\" Align=Center>\n"; $tableHead = "<tr> <th>Event</th> <th>Event</th> <th>Location</th> <th>Date</th> <th>Financial Year</th> </tr>\n"; while($row = mysql_fetch_array($query)){ $tablerow .= "<tr><td>".$row['eventid']."</td><td>".$row['eventname']."</td><td>".$row['eventlocation']."</td><td>".$row['eventdate']."</td><td>".$row['financialyear']."</td></tr>\n"; } $tableEnd = "</table>\n"; $note1 = "The table below shows the current programme list. To add a new event please enter a new 'UNIQUE' Event No (see from curent list) and then fill in all relevant fields in the table and then click on the Submit button."; ?> <p>&nbsp;</p> <?php $note2 = "Please note that dates must be typed in the following format yyyy-mm-dd.";?>The code for the form the user uses to add a new record is shown here:

<form id="form1" name="form1" method="post" action=""> <table width="31%" border="0" align="center"> <!--<tr> <td width="32%">eventid</td> <td width="68%"><input name="eventid" type="text" id="eventid" /></td> </tr>--> <tr> <td>eventname</td> <td><input name="eventname" type="text" id="eventname" class="<?php echo $class; ?>"/></td> </tr> <tr> <td>Location</td> <td><input name="eventlocation" type="text" id="eventlocation" /></td> </tr> <tr> <select name=eventtype> <option name=fundraiser value=fundraiser> fundraiser </option> <option name=profile value=profile> profile </option> <option name=other value=other> other </option> </select> <td>Type of Event</td> <td><input name="eventtype" type="text" id="eventtype" /></td> </tr> <tr> <td>Status</td> <td><input name="eventstatus" type="text" id="eventstatus" /></td> </tr> <tr> <td>Date</td> <td><input name="eventdate" type="Date" id="eventdate" /></td> </tr> <tr> <td>Start Time</td> <td><input name="starttime" type="text" id="starttime" /></td> </tr> <tr> <td>End Time</td> <td><input name="endtime" type="text" id="endtime" /></td> </tr> <tr> <td>Coordinator</td> <td><input name="coordinator" type="text" id="coordinator" /></td> </tr> <tr> <td>Comments</td> <td><input name="comments" type="text" id="comments" /></td> </tr> <tr> <td>Funds Raised</td> <td><input name="fundsraised" type="decimal(5,2)" id="fundsraised" /></td> </tr> <tr> <tr> <td>Fiancial Year</td> <td><input name="financialyear" type="YEAR" id="financialyear" /></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form></div></td> </tr></table>What I am trying to do is give the user a few options to enter the type of event (field eventtype). I want the user to be able to select an option and this selection is then added to the record after clicking on the submit button. I have managed to get the combo box but it is not doing anything and I don't know where to go from here. Can you help?

edbr
10-27-2010, 01:17 AM
could you not use a select box with your choices then update based on that

Beeky
10-27-2010, 07:49 AM
Could you possibly show me how to do this?

edbr
10-28-2010, 01:00 AM
sorry time challenged at the moment , but without looking too at you rexample i was thinking this. if your values existing are collected in a form , then as a select list you would have something like this
<form action="" method="get"><select name="ddd">
<option value="<?php echo $row['data'];?>" selected="selected">0</option>
<option value="value1">1</option>
<option value="value2">2</option>
</select></form>
names not correct of course then the value could be altered by changing the value in your form then on submit point it to an update statement upadate set ...