Jump to content

[SOLVED] passing variables help ... numbers and words ???


imarockstar

Recommended Posts

I am passing variables through a URL ... I have a file that redirects the user with a success code, like this :

 

header("Location: ../editsettings.php?hai=uploaded");

 

On the next page I have a message displayed based on what the passed variable is, like this :

 

<?php
if ( $hai == uploaded ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
?>

 

this is not working... does my variable that is passed need to be a number ? Is there a way to where I can use the if else statement with a word or a string of words ?

 

There are (most likely) two problems. Firstly, As MatthewJ showed, strings must be delimited by quotes. Otherwise, PHP treats them as constants. Now, if PHP cannot find a constant of that name, it will assume it was supposed to be a string. But, depending on your error reporting level, you may get errors. It's certainly not good practice to rely on this kind of thing.

 

Second, unless you have register_globals turned on (which you shouldn't), you need to retrieve the value from the $_GET array like so:

 

$hai = $_GET['hai'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.