Jump to content


Photo

Having problems passing variables.


  • Please log in to reply
4 replies to this topic

#1 epix

epix
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 July 2006 - 06:45 PM

Hello everyone, I appriciate that a place like this excists, so thanks in advance for the help.

Anyhow, I'm just getting started with learning PHP, and I've gotten everything installed with MySQL, have figrured out how to pass stuff into and out of the database, so thats why im so confused why I'm not getting this simple thing working.

Here is a sample code of the problem:

======[ variable.php ]=======
<html>
<body>

<?php

if ($submit) {
    echo "Something Submitted"; 
}
else{
    echo "Nothing Submitted"; 
}

php?>

</body>
</html>
==========[ END FILE ]=========

Now basically what I need to have happen is when i do this: http://localhost/variable.php?submit=1 or whatever it posts "Something Submitted", yet all i get is "Nothing Submitted", dosen't matter what I try, this always happenes.

I'm wondering if its some kind of option in PHP that i'm missing or what.

I'm running PHP Version 5.1.4, and again, all help is greatly appriciated.

Gissur Simonarson


#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 25 July 2006 - 07:04 PM

you need to use the superglobal $_GET to reference the query string. although you can change register_globals in php.ini to "true", it is not secure. so, to solve your problem:
if($_GET['submit'])
i guess you're reading some older books or books by lazy writers who always turn on register_globals...
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 July 2006 - 07:06 PM

The most likely cause is that register_globals is disbled in your php.ini file. This used to be enabled by default, but that setting was sited as making your script more insecure. When it is enabled, PHP would automagically create variables from the URL and POSTed forms. When it's disbaled, you need to obtain the values from either the $_GET superglobal array for variables coming from the URL or from forms using the GET method, or the $_POST superglobal array from POSTed forms. There are other superglobal arrays also. Read more about register_globals at http://www.php.net/register_globals

This being said, your simple script should look like:
<html>
<body>
<?php

if (isset($_GET['submit']) {
    echo "Something Submitted";   
}
else{
    echo "Nothing Submitted";   
}

php?>
</body>
</html>

Ken

#4 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 25 July 2006 - 07:07 PM

do you have register_globals on in PHP.ini ??? if so, you should turn it to off.  and if that's the case, you need to change your conditional to ($_GET['submit'] or $_POST['submit']) depending on how you have your HTML form submitting it's information.

#5 epix

epix
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 July 2006 - 09:16 PM

Thank you guys, appriciate it. Take it easy.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users