Page 1 of 1
drop down list, not directly connected to submit button
Posted: Fri Mar 31, 2006 7:00 pm
by rkc444
I have a problem, and have looked through many postings in this and other forums, and cannot find what I need.
I have a web page and a MySQL database. Most of the form contains text fields in which I capture data typed in by the user and it to a table in the MySQL database. That part works fine thus far. I also have a field which is a drop down box which gets its values from another table in the same MySQL database. That part works fine. But I cannot figure out how to store the selection, or selections, from the drop down box in the field so I can also write it to the table. I can find all sorts of help on capturing the value when that is all that is on the form. But I do not want the user to hit a button to select from the drop down box. I just want them to make their selection or selections, then go on to the next field. Ideally, there will be 3 or 4 such drop down boxes, and one submit button at the bottom. Any help?
Thanks.
Posted: Fri Mar 31, 2006 7:39 pm
by RobertGonzalez
Are you trying to capture the value of a listbox/combobox upon submission of the form? How you do this depends on the type of select field you are using (select versus select multiple). Please post back.
capturing several select fields
Posted: Sat Apr 01, 2006 11:09 am
by rkc444
Yes, I want to have the user type something into various text fields, and make selections from several drop down boxes. At least one of them will allow for multiple selections. One of them (country) will allow for only one selection. Then when the entire form is submitted, I want it to write all of the data to the MySQL table.
Posted: Sat Apr 01, 2006 1:14 pm
by RobertGonzalez
Regular select boxes act essentially the same as a text box. They will accept one value and pass one value. Multiple Select boxes will pass an array, so the way you set them up is as an array in your code. Take a look at these two pieces of html...
Code: Select all
<!-- THIS IS A SINGLE SELECT FIELD -->
<select name="fred">
<option value="flinstone">Fred Flintsone</option>
<option value="fender">Fred Fender</option>
<option value="krueger">Fred Krueger</option>
</select>
See how it differs from this one...
Code: Select all
<!-- THIS IS A MULTIPLE SELECT FIELD -->
<select multiple name="fred[]">
<option value="flinstone">Fred Flintsone</option>
<option value="fender">Fred Fender</option>
<option value="krueger">Fred Krueger</option>
</select>
In the second select field (a multiple) you declare the field name as an array so on the result page, you access it as an array var ($_POST['fred'] will be an array).
drop down box not working - my code
Posted: Sat Apr 01, 2006 2:25 pm
by rkc444
feyd | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Thanks again for your next response. I have no problem with a simple dwop down box, where I do not populate if via the MySQL table. Maybe the problem is that I am doing something wrong where I am trying to read from one table and write to another. Perhaps I have not dealt with that correctly. I have one section where I have a submit button. If I do not have the drop down box with the MySQL data in it, everything works fine. As follows:
Code: Select all
<?php
if (($_POST['submit']) and ($_POST['LName'])){ //if submit is clicked{
echo("Database connection successful.\n");
require("util.php");
$sql1 = new MySQL_class;
$sql1->Create("isei_trainee");
echo("Database connection successful.\n");
$Title=$_POST['Title'];
$FName=$_POST['FName'];
$LName=$_POST['LName'];
$InstName=$_POST['InstName'];
$Addr1=$_POST['Addr1'];
$Addr2=$_POST['Addr2'];
$City=$_POST['City'];
$StateProv=$_POST['StateProv'];
$PostCode=$_POST['PostCode'];
$Country=$_POST['Country'];
$Email=$_POST['Email'];
$sql1 = "INSERT INTO Submissions (Title, FName, LName, InstName, Addr1, Addr2, City, StateProv, PostCode, Country, Email) VALUES ('$Title', '$FName', '$LName', '$InstName', '$Addr1', '$Addr2', '$City', '$StateProv', '$PostCode', '$Country', '$Email')";
$result = mysql_query($sql1);
else {
echo "You have not entered your name";
mysql_close($result);
}
?>
</form>
But when I add the following, and get the drop down box with the MySQL data to appear, the other part no longer works, so the data is no longer writting to the MySQL table.
Code: Select all
<p class="body">Focus of Training: </p>
<blockquote>
<label>
<input type="checkbox" name="checkbox" value="checkbox">
</label>
<span class="body">discipline specific: </span>
<?php
require("util.php");
$sql2 = new MySQL_class;
$sql2->Create("isei_trainee");
echo("<p><ul><table border=1 cellpadding=4>\n");
$sql2 = mysql_query("SELECT disc_key, discipline FROM Disciplines ORDER BY discipline");
echo '<select name="Discipline">';
while ($row = mysql_fetch_array($sql2)) {
$sub = $row["discipline"];
$sub_id = $row["discipline"];
echo '<option value="' . htmlentities($sub_id) . '"';
if ($row['discipline'] == $operator ) {
echo ' selected="selected"';
}
echo '>' . htmlentities($sub) . '</option>';
}
echo "</select>";
?>
Does this help? Thanks again.
Russ
feyd | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Sun Apr 02, 2006 9:34 am
by RobertGonzalez
I'm wondering if this doesn't have something to do with the class you are using? Can you post the form code with and without the dropdown and the result code.