Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Hidden Field Contain Quotes, Help Please! 1

Status
Not open for further replies.

RaffiqEddy

Programmer
Jan 7, 2002
51
0
0
MY
Dear PHP Experts,

I have problem with hidden field contains quotes.

This is what I key-in in the text box:

" ~ ! @ # $ % ^ & * ( ) _ + ` - = | } { [ ] : ; ' ? > < , . / \

As u can see it’s all special characters.

To confirm what user has keyed-in, I display it and I stored it as a hidden field for the next process.

When I click submit button it automatically add slash to double/single quote, this solved my problem when I want to save the data into MySQL.

But the problem is, when I display the value, it shows like this:

Your text is:
\" ~ \\ ! @ # $ % ^ & * ( ) _ + ` - = | } { [ ] : ; \' ? > < , . /

<input type="hidden" name="test" value="\" ~ \\ ! @ # $ % ^ & * ( ) _ + ` - = | } { [ ] : ; \' ? > < , . /">

The code
Code:
<form name="form1" method="post" action="test.php">
<?
	if(isset($_POST[Submit]))
	{
		echo "<strong>Your text is:</strong><br>".$_POST[tText]."<br><br>";
		?>
		<input type="hidden" name="test" value="<? echo $_POST[tText];?>"><br><br>
		<?
	}
?>
        <input name="tText" type="text" id="tText">
        <input type="submit" name="Submit" value="Submit">
</form>

Any Idea how to solve this problem??

TIA & Regards.

Ps: I used PHP 4.3.4 + MySQL 3.32
 
Code:
<form name="form1" method="post" action="test.php">
<?
    if(isset($_POST[Submit]))
    {
        echo "<strong>Your text is:</strong><br>".$_POST[tText]."<br><br>";
        ?>
        <input type="hidden" name="test" value="<? echo stripslashes($_POST[tText)];?>"><br><br>
        <?
    }
?>
        <input name="tText" type="text" id="tText">
        <input type="submit" name="Submit" value="Submit">
</form>



stripslashes() will remove the slashes that addslashes adds.

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
stripslashes($_POST[tText)]

doh

stripslashes($_POST[tText])

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
The trouble stems from quotes within quotes or double quotes within double quotes.
A way to resolve this issue to use htmlspecialchars() before putting the info into HTML context.
 
Hi DRJ478, thank u very much, the solution given is exactly what I want, u make my day! -- A star for you...

Dear unborn, thank you, appreciate your time & efforts

Take care,

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top