Hi everybody. Thus far. I have successfully created a drop down menu. What I want is for someone to choose a selection from the drop down list in admin_page.php and click the Status button to view the status of the option chosen. For now, I created a status button that will go to status.php. Can someone help with some code that takes whats chosen in the drop down in admin_page.php and use in status.php? Any help is appreciated! thanks!

Snippet of my code: admin_page.php

<?
$adminID = $_SESSION['user_admin'];
$titleChosen = $_REQUEST['title'];

$sql="SELECT title FROM Election WHERE adminID ='$adminID'";
$result= mysql_query($sql);
$options="";
/**No elections? Handle with error if default "view an election" is chosen!*/

while ($row=mysql_fetch_array($result)) {
  $title=$row["title"];
  $options.="<OPTION VALUE=\"$title\">$title</OPTION>";
}

?>
<HTML>
<BODY>
...

<SELECT NAME="title" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">
<OPTION VALUE="0" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">View an election

<?
  echo $options;

?>

</SELECT>
<h2></h2>
<? statusButton();  //shows a status button that will go to status.php
?>
</BODY>
</HTML>

Its pretty simple...
place your select box inside a form and submit the form to status.php when status is clicked..
In status.php u can retrieve the selected value from

$selected = $_REQUEST['title'];

Hope this helps..
Cheers!!

Hi everybody. Thus far. I have successfully created a drop down menu. What I want is for someone to choose a selection from the drop down list in admin_page.php and click the Status button to view the status of the option chosen. For now, I created a status button that will go to status.php. Can someone help with some code that takes whats chosen in the drop down in admin_page.php and use in status.php? Any help is appreciated! thanks!

Snippet of my code: admin_page.php

<?
$adminID = $_SESSION['user_admin'];
$titleChosen = $_REQUEST['title'];

$sql="SELECT title FROM Election WHERE adminID ='$adminID'";
$result= mysql_query($sql);
$options="";
/**No elections? Handle with error if default "view an election" is chosen!*/

while ($row=mysql_fetch_array($result)) {
  $title=$row["title"];
  $options.="<OPTION VALUE=\"$title\">$title</OPTION>";
}

?>
<HTML>
<BODY>
...

<SELECT NAME="title" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">
<OPTION VALUE="0" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">View an election

<?
  echo $options;

?>

</SELECT>
<h2></h2>
<? statusButton();  //shows a status button that will go to status.php
?>
</BODY>
</HTML>

thank you. i understand now how it is if i had a form and and action to go to status.php. If I had multiple buttons that go to different pages but use whatever is selected in the drop down, how would that be different? the other buttons go to modify.php and upload.php.

thank you. i understand now how it is if i had a form and and action to go to status.php. If I had multiple buttons that go to different pages but use whatever is selected in the drop down, how would that be different? the other buttons go to modify.php and upload.php.

well AFAIK a form can be submitted to only 1 page...
There is a workaround for it though...
what u can do is submit the form to a common page say form_process.php regardless of which button is pressed...
now, in form_process.php retrieve ur select box value and store it in a session variable.
also retrieve the submit value to find which button was pressed and redirect the processing to corresponding page...
That should do the trick..
Hope i m clear..
Cheers!!

thanks! i'm going to try this tonight. So when I go to form_process.php, I will store the selected variable as $titleChosen = $_SESSION;
and that should retrieve what was in the drop down from the previous page? Also what line of code would redirect me to another page? Would it be similar to this:

header("Location: update.php");
Member Avatar for diafol
$title = $_POST['title'];

THis is all you need - but I'd suggest cleaning the form output with some function, minimum of addslashes() or if using this value in a DB use mysql_real_escape_string().

Don't use $_REQUEST as a simple querystring can mess this up for you (e.g. ww....../form_process.php?title=somethingstupid)

You DON'T need to use sessions for something as simple as this.

Just modify your code like this
------------
------------
#
<SELECT NAME="title" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">
#
<OPTION value="safety.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">View an election</option>
<OPTION value="some.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">some one</option>
<OPTION value="last.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">last song</option>
</SELECT>
#

#
<?
#
echo $options;
#

#
?>
#

#

thanks! i'm going to try this tonight. So when I go to form_process.php, I will store the selected variable as $titleChosen = $_SESSION;
and that should retrieve what was in the drop down from the previous page? Also what line of code would redirect me to another page? Would it be similar to this:

header("Location: update.php");

no buddy, its just the reverse...first u need to set the value in session variable..
in form_process.php what u need to do is

$_SESSION['title'] = addslashes($_POST['title']);

This will set a session variable with the selected option in drop down..
After doing this, u need to find which button was pressed by checking the button names in post variables and then accordingly redirect using header just as u mentioned...
in that specific page (update.php for example) u can retrieve the dropdown selected value simply by doing this

$titleChosen = $_SESSION['title'];

U Get it now??

You DON'T need to use sessions for something as simple as this.

The solution u suggested will get the post values from form and will store it in the form_process.php but what if i need that value in other page (update.php for instance)
Please tell me if u know any other method to transfer variables from one page to other... I ve been using sessions for this all the time.. Is there any drawback in it?

Member Avatar for diafol

You want to keep your sessions reasonably clear of crud. This screams of crud to me. Have an update procedure in your form processing file - no need to send it to another page.

If you use a custom update function as opposed to loads of SQL queries, it will simplify things considerably.

Hmm, just re-read your first post. You want the button to change depending on the value selected on the dropdown? If so, you can't use php without refreshing the page. You need to use javascript (or possibly ajax - depending on what you want to do).

the "onselect" html/js function should allow you to hide/show buttons depending on the value of the option chosen - easy if you create options in select from php.


BTW:

<SELECT NAME="title" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">
#
<OPTION value="safety.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">View an election</option>
<OPTION value="some.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">some one</option>
<OPTION value="last.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">last song</option>
</SELECT>

Yuk! Do not mess up your nice html with style attributes - keep them in CSS
Also, use lowercase for html tags if you need them to validate xhtml

You want to keep your sessions reasonably clear of crud. This screams of crud to me. Have an update procedure in your form processing file - no need to send it to another page.

If you use a custom update function as opposed to loads of SQL queries, it will simplify things considerably.

Hmm, just re-read your first post. You want the button to change depending on the value selected on the dropdown? If so, you can't use php without refreshing the page. You need to use javascript (or possibly ajax - depending on what you want to do).

the "onselect" html/js function should allow you to hide/show buttons depending on the value of the option chosen - easy if you create options in select from php.


BTW:

<SELECT NAME="title" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">
#
<OPTION value="safety.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">View an election</option>
<OPTION value="some.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">some one</option>
<OPTION value="last.html" style="font-size:11pt; font-family: arial,helvetica,sans-serif; color:#080000">last song</option>
</SELECT>

Yuk! Do not mess up your nice html with style attributes - keep them in CSS
Also, use lowercase for html tags if you need them to validate xhtml

Ohhkk thanx for clearing things up ardav... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.