944,098 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1185
  • PHP RSS
Nov 3rd, 2009
0

Select Menu Declaration in PHP

Expand Post »
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:

PHP Syntax (Toggle Plain Text)
  1. <select name="search" title="Search Criteria">
  2. <option value="id">ID Status</option>
  3. <option value="ip">IP Status</option>
  4. <option value="pd">PD Status</option>
  5. <option value="nva">NVA Status</option>
  6. </select>

Thank you!
Last edited by levsha; Nov 3rd, 2009 at 1:30 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
levsha is offline Offline
137 posts
since Nov 2009
Nov 4th, 2009
0
Re: Select Menu Declaration in PHP
First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: Select Menu Declaration in PHP
Click to Expand / Collapse  Quote originally posted by network18 ...
First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.
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.
Reputation Points: 10
Solved Threads: 0
Junior Poster
levsha is offline Offline
137 posts
since Nov 2009
Nov 4th, 2009
0
Re: Select Menu Declaration in PHP
Click to Expand / Collapse  Quote originally posted by levsha ...
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.
Still you not describing, what exactly you expect from the PHP, even though this is a proper English than your first post.
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.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: Select Menu Declaration in PHP
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.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
violarisgeorge is offline Offline
15 posts
since May 2009
Nov 5th, 2009
0
Re: Select Menu Declaration in PHP
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.
Let's say I have this in my HTML form:
PHP Syntax (Toggle Plain Text)
  1. <select name="search" title="Search Criteria">
  2. <option value="id">ID Status</option>
  3. <option value="ip">IP Status</option>
  4. <option value="pd">PD Status</option>
  5. </select>

Here is my PHP:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $search = @$_POST['search'];
  4. $id = @$_POST['id'];
  5. $ip = @$_POST['ip'];
  6. $pd = @$_POST['pd'];
  7.  
  8. ?>

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 6:40 pm. Reason: Added code tags. Please use them to format any code that you post.
Reputation Points: 10
Solved Threads: 0
Junior Poster
levsha is offline Offline
137 posts
since Nov 2009
Nov 5th, 2009
0
Re: Select Menu Declaration in PHP
Click to Expand / Collapse  Quote originally posted by levsha ...
Let's say I have this in my HTML form:
PHP Syntax (Toggle Plain Text)
  1. <select name="search" title="Search Criteria">
  2. <option value="id">ID Status</option>
  3. <option value="ip">IP Status</option>
  4. <option value="pd">PD Status</option>
  5. </select>

Here is my PHP:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $search = @$_POST['search'];
  4. $id = @$_POST['id'];
  5. $ip = @$_POST['ip'];
  6. $pd = @$_POST['pd'];
  7.  
  8. ?>

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[???]')";
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)
  1. $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.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
violarisgeorge is offline Offline
15 posts
since May 2009
Nov 8th, 2009
0
Re: Select Menu Declaration in PHP
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)
  1. $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!
Reputation Points: 10
Solved Threads: 0
Junior Poster
levsha is offline Offline
137 posts
since Nov 2009
Nov 8th, 2009
0
Re: Select Menu Declaration in PHP
Click to Expand / Collapse  Quote originally posted by levsha ...
Thank you so, so, so much!
It works perfectly well!
I am glad I could help! You should mark this thread solved so others can benefit from it.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
violarisgeorge is offline Offline
15 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Warning: mysql_connect()
Next Thread in PHP Forum Timeline: Creating dynamic links with smarty.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC