Skip to main content
GameDev.net gamedev.net
🔒 Locked

PHP global variables

Started by Cygnus_X Apr 18, 2004 at 5:38 PM 3 replies 350+ views
Original Post
Cygnus_X
Cygnus_X
I'm trying to make a very simple poll useing PHP. The problem I'm haveing is that I want the poll and the results to appear on the same page (ie, if the user hasn't voted, show the poll, if he has, show the results). My attempt to make this happen looks a little like this... function make_poll(){ if(!isset(HTTP_POST_VARS['vote'])){ display_poll(); } else { display_poll_results(); } } where the function display_poll() is a simple HTML form with radio buttons whos name is vote and value varries depending on what you vote for. But, for some reason, PHP doesn't like this as it never registers a value for 'vote'. I've tried changing the submit action of the form to an inbetween page which uses HTTP_SESSION_VARS['vote'] = HTTP_POST_VARS['vote'] (which seems to work) and then have that page forward back to the poll page, but when I try to pass the session var vote back, PHP keeps seeing it as empty... what could I possibly be doing wrong? [edited by - Cygnus_X on April 18, 2004 6:39:40 PM]
intransigent-seal
intransigent-seal
$HTTP_POST_VARS isn''t a "superglobal" variable in PHP. It will not be available in a function unless you use
function foo()
{
global $HTTP_POST_VARS;
...
}

From version 4.1.0 of PHP, there are new variables to use instead of $HTTP_POST_VARS. These are named $_POST, $_GET, $_SESSION and so on, and are automatically available at any scope.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Puzzler183
Puzzler183
Don''t know what kind of PHP you use, but all variables are prefixed with $... Anyway, you should be using $_POST[''vote''] and not whatever you are O_o.
CProgrammer
CProgrammer
do something like this:


if($_REQUEST[''action''] == View)
{
display_poll();
}
else
{
display_poll_results();
}


voila
-CProgrammer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.