| | |
Select Menu Declaration in PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 27
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; 25 Days Ago at 1:30 pm.
•
•
Join Date: Sep 2009
Posts: 525
Reputation:
Solved Threads: 61
0
#2 24 Days Ago
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: 27
Reputation:
Solved Threads: 0
0
#3 24 Days Ago
•
•
•
•
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: 525
Reputation:
Solved Threads: 61
0
#4 24 Days Ago
•
•
•
•
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 24 Days Ago
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: 27
Reputation:
Solved Threads: 0
0
#6 22 Days Ago
•
•
•
•
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; 22 Days Ago at 6:40 pm. Reason: Added code tags. Please use them to format any code that you post.
0
#7 22 Days Ago
•
•
•
•
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: 27
Reputation:
Solved Threads: 0
0
#8 20 Days Ago
•
•
•
•
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.
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





