| | |
Select Menu Declaration in PHP
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 40
Reputation:
Solved Threads: 0
How do you declare your select menu in the PHP?
Does it have to be an array of variables? One single variable?
Something else?
Let's say this one:
Thank you!
Does it have to be an array of variables? One single variable?
Something else?
Let's say this one:
PHP Syntax (Toggle Plain Text)
<select name="search" title="Search Criteria"> <option value="id">ID Status</option> <option value="ip">IP Status</option> <option value="pd">PD Status</option> <option value="nva">NVA Status</option> </select>
Thank you!
Last edited by levsha; Nov 3rd, 2009 at 12:30 pm.
•
•
Join Date: Sep 2009
Posts: 607
Reputation:
Solved Threads: 70
0
#2 Nov 4th, 2009
First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
•
•
Join Date: Nov 2009
Posts: 40
Reputation:
Solved Threads: 0
0
#3 Nov 4th, 2009
•
•
•
•
First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.
What I mean is I need to write an IF... ELSE statement in PHP using data from the select menu that comes from my HTML form.
Can't figure out how this should be done.
•
•
Join Date: Sep 2009
Posts: 607
Reputation:
Solved Threads: 70
0
#4 Nov 4th, 2009
•
•
•
•
Yes, I know.
What I mean is I need to write an IF... ELSE statement in PHP using data from the select menu that comes from my HTML form.
Can't figure out how this should be done.
I assume you have some html form and in another page you putting those inputs in the select ekement.
For example in your first html form you ask the user to input his qualification etc.He enters Xth,XIIth, Grad and Post-grad details and then next form carries the data and displayed in the select element.
If I am wrong correct me.
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
0
#5 Nov 4th, 2009
Simply, if I understand what you want to do, you should have a value for each option in your HTML select element of your form. Then, in php, you should have variables which grab those option values (with $_POST or $_GET depending on your form), and then feed them into a switch statement (better than IF statement for this purpose I believe) and put inside each case of your switch what you want it to do for each option.
i.e. each case represents one of the options.
i.e. each case represents one of the options.
I take your reality and substitute my own
violarisgeorge.com
violarisgeorge.com
•
•
Join Date: Nov 2009
Posts: 40
Reputation:
Solved Threads: 0
0
#6 Nov 5th, 2009
•
•
•
•
Simply, if I understand what you want to do, you should have a value for each option in your HTML select element of your form. Then, in php, you should have variables which grab those option values (with $_POST or $_GET depending on your form), and then feed them into a switch statement (better than IF statement for this purpose I believe) and put inside each case of your switch what you want it to do for each option.
i.e. each case represents one of the options.
PHP Syntax (Toggle Plain Text)
<select name="search" title="Search Criteria"> <option value="id">ID Status</option> <option value="ip">IP Status</option> <option value="pd">PD Status</option> </select>
Here is my PHP:
PHP Syntax (Toggle Plain Text)
<?php $search = @$_POST['search']; $id = @$_POST['id']; $ip = @$_POST['ip']; $pd = @$_POST['pd']; ?>
Is that correct?
What if I need to grab a value from my HTML select element (one of the options) and send it to a database?
What do I write in my INSERT statement?
$sql = "insert into mytable (status) values ('$_POST[???]')"; Last edited by Ezzaral; Nov 5th, 2009 at 5:40 pm. Reason: Added code tags. Please use them to format any code that you post.
0
#7 Nov 5th, 2009
•
•
•
•
Let's say I have this in my HTML form:
PHP Syntax (Toggle Plain Text)
<select name="search" title="Search Criteria"> <option value="id">ID Status</option> <option value="ip">IP Status</option> <option value="pd">PD Status</option> </select>
Here is my PHP:
PHP Syntax (Toggle Plain Text)
<?php $search = @$_POST['search']; $id = @$_POST['id']; $ip = @$_POST['ip']; $pd = @$_POST['pd']; ?>
Is that correct?
What if I need to grab a value from my HTML select element (one of the options) and send it to a database?
What do I write in my INSERT statement?
$sql = "insert into mytable (status) values ('$_POST[???]')";
Then, in your db query you should command something like
PHP Syntax (Toggle Plain Text)
$sql = "INSERT INTO `mytable` (status) VALUES ($search);"
IMPORTANT NOTE: The SQL query should go into EVERY single on of your case statements of the switch. I hope you get what I mean... Try it out and report back any problems.
I take your reality and substitute my own
violarisgeorge.com
violarisgeorge.com
•
•
Join Date: Nov 2009
Posts: 40
Reputation:
Solved Threads: 0
0
#8 Nov 8th, 2009
•
•
•
•
No this is not correct. You only need $search = @$_POST['search']; in order to capture the selection. Then in your switch statement you should say that if the $search is equal to id, then do this, and so on.
Then, in your db query you should command something like
PHP Syntax (Toggle Plain Text)
$sql = "INSERT INTO `mytable` (status) VALUES ($search);"
IMPORTANT NOTE: The SQL query should go into EVERY single on of your case statements of the switch. I hope you get what I mean... Try it out and report back any problems.
Thank you so, so, so much!
It works perfectly well!
![]() |
Similar Threads
- WAP+php (PHP)
- PHP Dynamic Form HELP! (PHP)
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- PHP Form, SQL connectivity issues, please help. (MySQL)
- populate a select box using PHP (PHP)
- PHP e-mail SMTP error ??? (PHP)
- PHP E-mail setting ??? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Warning: mysql_connect()
- Next Thread: Creating dynamic links with smarty.
Views: 610 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for PHP
ajax apache array box broken buttons cakephp cart check checkbox class cms code combobox cookies css database date delete directory display download dropdown drupal dynamic echo email error file files folder form forms function functions header hosting href htaccess html image include insert ip java javascript joomla limit link list login lookup loop mail menu methods mlm mod_rewrite multiple mysql order parse paypal php problem query radio random recursion regex remote results rows script search select server session sessions sort sorting source speed sql string table unicode update updates upload url user validation variable video web website wordpress xml zend





