Jump to content

Having problems passing variables.


epix

Recommended Posts

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
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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:
[code]<html>
<body>
<?php

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

php?>
</body>
</html>[/code]

Ken
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.