Page 1 of 1

URLDECODE does not "uncode" what the URLENCODE did

Posted: Wed Sep 25, 2002 10:23 am
by PingLeeQuan
i've been spening my wheels all yesterday trying to figure this one out......

i have a utility that allows the user to change the "html" button on the website based on teh access level of teh user.

When i type the information for the button (i.e, a href IMG...) it takes it and inerts it to teh table ok. When i reteive it, it actually translates teh html code and displays teh button as it would on teh web site instead of displaying the code for it.

I used URLENCODE when reading from the database that way the browser does not translate teh tags, i change what whatever i need and update the database.

The problem is before updating teh DB, i need to DECODE what the ENCODE did. This is where i run into problem.

It does not seem to decode correctly and the UPDATE stement bombs

this is a sample button value

$ButtonValue='<A HREF="MySkel.php?iam=AboutUs" onMouseOver="F_roll(''NavigationButton1'',1)" onMouseOut="F_roll(''NavigationButton1'',0)"><IMG ID="NavigationButton1" NAME="NavigationButton1" HEIGHT=38 WIDTH=146 SRC="../assets/images/autogen/About_Us_Np1.gif" onLoad="F_loadRollover(this,''About_Us_NRp3.gif'')" BORDER=0 ALT="About Us"></A>'


i am after $ButtonValue.

When i retrieve it from the DB it is in the Pure Html Format---
.....i display

$row = mysql_fetch_assoc($result);

echo " <td colspan='5'><textarea cols=25 rows=4 name='ButtonValue'>". urlencode($row['ButtonValue']) . "</textarea></td></tr>";

(This displays the button kind of encoded and difficult to navigate... but it is ok... the problem is when i try to save it back to teh DB (even if i did not change anything, it gives me an error.
SAMPLE DISPLAY
%3CA+HREF%3D%22.%2FMySkel.php%3Fiam%3DAboutUs%22+onMouseOver%3D%22F_roll%28%27NavigationButton1%27%2C1%29%22+onMouseOut%3D%22F_roll%28%27NavigationButton1%27%2C0%29%22%3E%3CIMG+ID%3D%22NavigationButton1%22+NAME%3D%22NavigationButton1%22+HEIGHT%3D38+WIDTH%3D146+SRC%3D%22.%2Fassets%2Fimages%2Fautogen%2FAbout_Us_Np1.gif%22+onLoad%3D%22F_loadRollover%28this%2C%27About_Us_NRp3.gif%27%29%22+BORDER%3D0+ALT%3D%22About+Us%22%3E%3C%2FA%3E


When i update, even if i do not change anything, it bombs.
UPDATE STATEMENT
$UpdateQry = "update tButton set
ButtonName='" . $ButtonName . "',
ButtonValue=" . urldecode($ButtonValue) . ",
ButtonDescription='" . $ButtonDescription ."',
ButtonStateOver=" . $tempvarover . ",
ButtonStateNormal=" . $tempvarnormal . ",
ButtonStateDown=" . $tempvardown . ",
ButtonTopNav=" . $TopNav . ",
ButtonOrder=" . $ButtonOrder . ",
Active=" . $ButtonActive ." where ButtonID = " . $WorkID;
$result = mysql_query($UpdateQry);

Any suggestions?

Re: URLDECODE does not "uncode" what the URLENCODE

Posted: Wed Sep 25, 2002 10:28 am
by twigletmac
PingLeeQuan wrote:I used URLENCODE when reading from the database that way the browser does not translate teh tags, i change what whatever i need and update the database.
It sounds like you probably want to use htmlspecialchars() instead of urlencode().

Mac