开发者

Show last submitted value in search box

开发者 https://www.devze.com 2023-03-09 02:02 出处:网络
I have a text box in an HTML form where the user will input some information and press submit. This data will be submitted to the same page, so I want to show in the text box the last submitted value.

I have a text box in an HTML form where the user will input some information and press submit. This data will be submitted to the same page, so I want to show in the text box the last submitted value.

I was trying this:

<input name="srq" type="text" id="search_box" <开发者_StackOverflow社区;?php if($_GET["srq"]) echo 'value="'.$_GET["srq"].'"'; ?> />

But that will turn "'hello'" into "\'hello\'". What is the right way to do this?


One solution may be to turn off the magic_quotes_gpc in php settings or other one is to use stripslashes in $_GET["srq"]

<?php if($_GET["srq"]) echo 'value="'.stripslashes($_GET["srq"]).'"'; ?>

I presume you understand how unsecured is that?


echo 'value="' . htmlspecialchars($_GET['srq']) . '"'

And don't add slashes automatically. If you need to insert something in the database, escape it with the db escape function (such as mysql_real_escape_string() for MySQL) instead of relying on slashes.


use the stripslashes function when outputting the value.


you have magic quotes = On

use get_magic_quotes_gpc to check if they are on and then use stripslashes to remove the quotes

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号