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 ?

 

Link to comment
Share on other sites

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'];

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.