473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to get the values of an HTML <select> tag using PHP

kosaks
10
Hello to everyone!

I would like to ask if how can i get the selected value of an HTML <select> tag using PHP. Im new to PHP and MYSQL programming. This is my code.

[HTML]

<form method="POST" name="me">
<select size="1" name="DropDownBox">
<option value="99">Default</option>
<option value="1">Choice 1</option>
<option value="2">Choice 2</option>
<option value="3">Choice 3</option>
<option value="4">Choice 4</option>
</select><input type="submit" value="Submit" name="BTN"/></p>
</form>

[/HTML]

[PHP]

if(isset($_POST['BTN'])){
$value = $_POST['DropDownBox'];
$con = mysql_connect("localhost","sample","test");
mysql_selectdb("sampleDB",$con);
$SQL = "INSERT INTO selectedChoices (`choices`) VALUES ('$value');";
mysql_query($SQL, $con);
}
$mysql_close($con);

[/PHP]

The data is saved to the database but im wondering because every time i save a new record the value in the database is the first value in my <select> tag which is the "Default" value. I don't know why php can't get the selected value on my <select> tag. Can someone correct me with my errors.

Any help will be appreciated!

Thanks in advance

Jeff
Jun 27 '11 #1

✓ answered by code green

Probably because you haven't specified to where you are posting eg
Expand|Select|Wrap|Line Numbers
  1. <form method="POST" name="me"
  2. action="path/to/my.php">

1 10320
code green
1,726 Expert 1GB
Probably because you haven't specified to where you are posting eg
Expand|Select|Wrap|Line Numbers
  1. <form method="POST" name="me"
  2. action="path/to/my.php">
Jun 27 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Raghuram Banda | last post by:
Hi All, Can any one help me, how to get the selected value from <Select> tag using DOM I tried with document.getElementById("selectTagId").getAttribute("value") it's working fine with IE but...
2
by: Mad Scientist Jr | last post by:
I'm trying to get javascipt select all items in a HTML form <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all get...
7
by: | last post by:
I can't get IE 6 to read the values in my <SELECT..> data entry fields. Netscape 7 and Opera see them, and IE will pass the values to the database, but the javascript validation script gets a null...
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
1
by: Knut-Frode Dagestad | last post by:
I have a <selectlist in some html code with hundreds of options. Is it possible to use javascript to jump to the next/previous item in the list? Knut-Frode
7
by: lambertb | last post by:
Hi, is this possible to achieve this, and how? http://img217.imageshack.us/img217/779/derrrvw2.png thanks!
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.