Forum Moderators: coopster

Message Too Old, No Replies

drop down menu not passing 'subject' variable to DB

         

amdorsey

4:58 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



I have a simple form that send info to my DB, if I have a textfield with a value of 'subject' it passes fine. If I use my dropdown menu with the same value of 'subject'

Here is my simple form, Any reason why the dropdown is not passing the value correctly?

echo "<form action=\"doadd.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"user\" value=\"$usersname\">";
echo "Please Choose a Support Subject:<br><br>";
echo "<select name=\"select\">";
echo "<option value=\"null\" selected>Choose...</option>";
echo "<option value=\"subject\">SUBJECT: Email Troubles</option>";
echo "<option value=\"subject\">SUBJECT: Website Down (not active)</option>";
echo "<option value=\"subject\">SUBJECT: Request a Service</option>";
echo "<option value=\"subject\">SUBJECT: Change Services</option>";
echo "<option value=\"subject\">SUBJECT: Billing Inquiry</option>";
echo "<option value=\"subject\">SUBJECT: Change Billing Options</option>";
echo "<option value=\"subject\">SUBJECT: MISC</option>";
echo "<option value=\"subject\">SUBJECT: User Defined</option>";
echo "</select><br><br>";
echo "Support Description:<br><br>";
echo "<textarea name=\"ticket\" rows=\"10\" cols=\"25\"></textarea><br>";
echo "<br><br><input type=\"submit\" value=\"Add Ticket\">";
echo "</form>";

HelenDev

5:07 pm on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there,

I think it is because the value of each option will always be "subject". You need to give them different all different values relating to what they are.

amdorsey

6:11 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



Can you expand on waht you are talking about? Give Examples?

Warboss Alex

6:25 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



Because the value which is passed to $_POST is the 'value' attribute of the option. Your values are all the same:

<option value="subject">SUBJECT: Email Troubles</option>
<option value="subject">SUBJECT: Website Down</option>
<option value="subject">SUBJECT: Request A Service</option>

They've all got a 'value' of 'subject'. So doing a
print $_POST['select'] would output 'subject' no matter which option was selected.

You need to change the values, i.e. something like this:

<option value="email_troubles">SUBJECT: Email Troubles</option>
<option value="website_down">SUBJECT: Website Down</option>
<option value="request_a_service">SUBJECT: Request A Service</option>

Change this for all your options, then doing a print $_POST['select'] would output the value defined in the form.
Ex: (using the three fields above)
(Selected "SUBJECT: Email Troubles")
print $_POST['select'];
//output: email_troubles

This should clear things up for you.

dreamcatcher

6:27 pm on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you are getting confused with how you pass data from a drop down menu. Your menu has the name "select" so by echoing this variable, it will display what is set as the value. In your case "subject" will be set for anything that is selected.

If you just want to have whats selected pass to the database use:


echo "<select name=\"select\">";
echo "<option value=\"null\" selected>Choose...</option>";
echo "<option>SUBJECT: Email Troubles</option>";
echo "<option>SUBJECT: Website Down (not active)</option>";
echo "<option>SUBJECT: Request a Service</option>";
echo "<option>SUBJECT: Change Services</option>";
echo "<option>SUBJECT: Billing Inquiry</option>";
echo "<option>SUBJECT: Change Billing Options</option>";
echo "<optio>>SUBJECT: MISC</option>";
echo "<option>SUBJECT: User Defined</option>";

This will simply add what you see to the database when you access your "select" variable.

$select = $_POST['select'];

echo $select;

Alternatively you can assign values to each field:


echo "<select name=\"select\">";
echo "<option value=\"null\" selected>Choose...</option>";
echo "<option value=\"1\">SUBJECT: Email Troubles</option>";
echo "<option value=\"2\">SUBJECT: Website Down (not active)</option>";
echo "<option value=\"3\">SUBJECT: Request a Service</option>";
echo "<option value=\"4\">SUBJECT: Change Services</option>";
echo "<option value=\"5\">SUBJECT: Billing Inquiry</option>";
echo "<option value=\"6\">SUBJECT: Change Billing Options</option>";
echo "<option value=\"7\">SUBJECT: MISC</option>";
echo "<option value=\"8\">SUBJECT: User Defined</option>";

In this case if you echoed $select you would see 1, 2, 3 etc...

Hope that helps.

:)