epix Posted July 25, 2006 Share Posted July 25, 2006 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><?phpif ($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 Quote Link to comment https://forums.phpfreaks.com/topic/15614-having-problems-passing-variables/ Share on other sites More sharing options...
ryanlwh Posted July 25, 2006 Share Posted July 25, 2006 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:[code]if($_GET['submit'])[/code]i guess you're reading some older books or books by lazy writers who always turn on register_globals... Quote Link to comment https://forums.phpfreaks.com/topic/15614-having-problems-passing-variables/#findComment-63565 Share on other sites More sharing options...
kenrbnsn Posted July 25, 2006 Share Posted July 25, 2006 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_globalsThis being said, your simple script should look like:[code]<html><body><?phpif (isset($_GET['submit']) { echo "Something Submitted"; }else{ echo "Nothing Submitted"; }php?></body></html>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/15614-having-problems-passing-variables/#findComment-63567 Share on other sites More sharing options...
thepip3r Posted July 25, 2006 Share Posted July 25, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15614-having-problems-passing-variables/#findComment-63570 Share on other sites More sharing options...
epix Posted July 25, 2006 Author Share Posted July 25, 2006 Thank you guys, appriciate it. Take it easy. Quote Link to comment https://forums.phpfreaks.com/topic/15614-having-problems-passing-variables/#findComment-63641 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.