Joe
Joe

Reputation: 31

passing a variable in a URL twice

is there a limit to the amount of times you can pass a variable in a URL? I have opened up a page after doing an AJAX call and I'm passing the mid variable through fine.

 window.open('articlecrop.php?id='+ result.mid, '_self');

I get the variable in php, do some unrelated stuff, then forward it through...

  $id = $_GET['id'];
   if( isset($_POST['submit']) )
    {header("Location: articlesave.php?filename=$filename&height=$orig_h&id=$id");
}

But the variable doesn't go through.

I've tried to echo the $id on to the screen and it works. I've also tried changing the $id field to some random text and it passes, so I know there isn't anything wrong with me pulling and passing the variable.

The problem seems to be in that I'm taking a variable from a URL, then passing it on again in the URL. Does anyone have a way around that?

   <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
            <p>
                <label for="image">Image</label>
                <input type="file" name="image" id="image">
                <br />
            </p>
            <p>
                <input type="submit" name="submit" value="Upload image" />
            </p>
        </form>

Upvotes: 0

Views: 601

Answers (2)

Joe
Joe

Reputation: 31

I've figured it out. The id variable that I pulled from the URL was lost when I submitted the form. To get around this I...

pulled the variable on page load

$id = $_GET['id']; 

then passed it in a hidden field on the form.

<input type="hidden" name="mid" id="mid" value="<?php echo $id; ?>">

pulled it on the form submission

$mid = $_POST['mid'];

then added it to the URL

header("Location: articlesave.php?filename=$filename&height=$orig_h&id=$mid");

Upvotes: 0

mahbubcsedu
mahbubcsedu

Reputation: 158

It's difficult to answer based on your question as you have provided just two lines of your code. There is no problem in passing variable more than once. As long as you are creating new url and executing that url, you can always add variables even it the same variable you have received from GET.

Upvotes: 1

Related Questions