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:

<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!

Edited by levsha: n/a

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by violarisgeorge
0

First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.

0

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.

0

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.

0

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.

0

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:

<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

$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[???]')";

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Let's say I have this in my HTML form:

<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

$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[???]')";

No this is not correct. You only need $search = @$_POST; 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

$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.

0

No this is not correct. You only need $search = @$_POST; 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

$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!

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.