-1

I am trying to pass an action parameter and a variable parameter in the same header function.

Here is the code that I have written so far:

header('Location: .?action=show_edit_form, word=$word');

When I use the action parameter alone, it goes to the next page, but when I try to pass a variable along with the action parameter, it does not work.

Please advise.

1

3 Answers 3

2
  1. Query string parameters in URLs are separated by & not by ,
  2. PHP doesn't interpolate variables inside strings quoted with ', you need "
  3. Although most browsers will silently error correct, the Location header requires an absolute URI

Thus:

header("Location: http://example.com/foo.php?action=show_edit_form&word=$word");

Unless you are certain your variable won't have special characters in it, you should make sure it is properly encoded for putting in a URL too.

header("Location: http://example.com/foo.php?action=show_edit_form&word=" . urlencode($word));
Sign up to request clarification or add additional context in comments.

Comments

0

What you are doing with the header is just referring the user to another page that conforms to a normal url.

Header('Location: .?action=show_edit_form& word='.$word);

On that page you can call $_GET['word']. You may also want to urlencode your values to prevent any unforseen problems with invalid characters. Look carefully at you quotation marks inside the header function.

Comments

0

For Example,

    Here i am trying to send the parameter id & message for the purpose of deleting record,So you  
    use the following code,

             $Params="?action=delete&id=".$id."&mess=Deleted Sucessfully"; 

             header("Location:company.php".$Params);

    So , in the next page you will get the parameter variable as,

             $action=$_GET['action'];

             $id=$_GET['id'];

             $message=$_GET['mess'];


    Above is the format of passing multiple parameters.Hope it works...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.