Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple HTML form & PHP query

Status
Not open for further replies.

jpmad4it2005

Programmer
Jan 25, 2006
5
GB
hello

i have a HTML form (which the user completes) that submits the information in it to a PHP script which then compiles the information and enters it into a database. It does this by using the POST method. The problem is not all the data is being passed to the Database. I have noticed that the fields which have data missing from them is where the form is of the drop-down list type e.g. title -> mr, mrs, miss, Dr. Can anyone tell me what i need to do to pass the drop-down list information to the PHP script and then to the database? all the other information in the form is being passed totally fine.

any help will be great
J
 
There is no difference between a <SELECT> and any other type of form input. In your case the value will be in an element of $_POST.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
im sorry i don't understand that? sorry im a bit of a newbie.

are you saying that the data will be in the $_POST variable? If so, how do io retrieve that information??
 
If you submit a POST method form to a PHP script, all the values from the fields in the form will appear as elements of the predefined superglobal array $_POST. (see
For example, when the form:

<form method="post" action="somescript.php">
<input type="text" name="foo"><br>
<input type="text" name="bar"><br>
<input type="submit">
</form>

is submitted to somescript.php, when somescript.php is run by the server $_POST will contain two elements, $_POST['foo'] and $_POST['bar'], which will hold the submitted values from the two fields.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
ok thanks.

So for example i have the following snippet of code:

mysql_query("INSERT INTO entry (date, title, forename) VALUES ('$date','$title','$forename')")
or die("error");

If, for example, the field named title is of the drop-down list type in the HTML form, how would i attach the value in $_POST['Mr'] (say that the user selected Mr from the drop down list) to the variable $title, and therefore pass it to the database?
 
also a problem occurs because the drop down list is as follows:

<select name="title">
<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Dr</option>
</select>

which is different to :

<form method="post" action="somescript.php">
<input type="text" name="foo"><br>
<input type="text" name="bar"><br>
<input type="submit">
</form>

in the latter it is possible to name each input type, whereas in the drop down list there is only the opportunity to name the whole selection, and not each input separately
 
There is no difference. If a form field named "foo" is submitted from a POST-method form, the value of that field will be in $_POST['foo']. It does not matter what type of field it is.

There will never be a $_POST['Mr']. There will only be a $_POST['title']. If the user selected "Mr" within the "title" form field and submitted, the $_POST['title'] will contain the value "Mr".

$_POST is an array, and the names of the elements of the array will match the names of your form fields. The values in those elements will match submitted values.


Again, read the tutorial in the PHP online manual ( paying particular attention to the page titled "Dealing with forms" (
Want the best answers? Ask the best questions!

TANSTAAFL!!
 
thanks, i fixed it.

the problem is here

<select name="title">
<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Dr</option>
</select>

i didnt give each value a name. The following is correct:

<select name="title">
<option value="Mr">Mr
<option value="Mrs">Mrs
<option value="Miss">Miss
<option value="Dr">Dr
</select>


so simple
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top