Re: & terminates string?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Perry, Matthew (Fire Marshal's Office) wrote:
I am using PHP 4.3.1 and running Apache Server and MySQL.

The following question is probably only related to PHP.



Here is the problem:



I am passing the following string from one form to another:

"../create.php?dest=Employee/menu_handleemployee.php?action=update&ID=$ID"



Here is the actual code:

<form
action="../create.php?dest=Employee/menu_handleemployee.php?action=update&ID
=<?echo $ID;?>" method="post" enctype="multipart/form-data"
name="form1EMPLOYEE">



When I view the source it comes out as expected:

<form
action="../create.php?dest=Employee/menu_handleemployee.php?action=update&ID
=82"


method="post" enctype="multipart/form-data" name="formEMPLOYEE">



But after it goes to the next page it turns into this:

"../create.php?dest=Employee/menu_handleemployee.php?action=update"

Everything up to and after the '&' disappears!!


that because PHP sees your URL as having two GET vars:

dest=Employee/menu_handleemployee.php?action=update
ID=82

the ampersand is the default name/value pair seperator.

try using urlencode() [and urldecode() when you actually want to redirect to that 'dest' url] on the redirect string when passing it along in the URL (or form field)

e.g.

$action = '../create.php?dest='.urlencode("Employee/menu_handleemployee.php?action=update&ID=$ID");



and if that doesn't work try replacing the '&' char with something else e.g.

$action = '../create.php?dest='.str_replace('&','$$',"Employee/menu_handleemployee.php?action=update&ID=$ID");

and then before your redirect to that url reverse the replacement e.g.:

header('location: ' . str_replace('$$','&',"Employee/menu_handleemployee.php?action=update&ID=$ID"));
exit;




BTW: 2 dollar signs may not be the best choice of chars to use.



another way of tackling the issue is by looking at the contents of $_SERVER (a auto superglobal var, just like $_GET, $_POST etc) - try:

print_r($_SERVER);

you'll be surprised what kinds of useful items are contained in that array.

while you're at it try:

print_r($_GET);

looking at the output of that will probably help you understand where the 'ID' bit of the redirect url went.

<RANT>

print_r() is your friend USE IT!!! OFTEN!!!

sing this as a reminder "When in doubt print it out"
[ (tm) Wong Coding Industries ;-) ]

</RANT>


The goal of this code is to send the redirect address to the form that
modifies my data.


I want variable "dest" to be used to dynamically redirect the page.



I have tried the following to fix the problem without avail:

1) I tried saving the variable in other ways such as text fields in the form
itself.

2) I tried addslashes() (which works well with similar problems related to
', " etc.).

3) I tried adding \ before &

4) I danced around my computer and threatened to pull the plug.

you forgot to wave the dead chicken around your head!


None of these worked!





What is it about '&' that throws everything off with PHP variables?  It
doesn't seem to be a problem with HTML.

its the default request name/value pair seperator.


This is exceedingly difficult to research online because '&' is excluded from most search engines automatically.

it's called an ampersand. which might help further searching.




-Matthew









-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux