English 中文(简体)
在搜索框中显示上次提交的值
原标题:Show last submitted value in search box
  • 时间:2011-05-26 19:38:08
  •  标签:
  • php
  • html

我有一个HTML表单中的文本框,用户将在其中输入一些信息并按提交。这些数据将提交到同一页面,所以我想在文本框中显示上次提交的值。

我试着这样做:

<input name="srq" type="text" id="search_box" <?php if($_GET["srq"]) echo  value=" .$_GET["srq"]. " ; ?> />

但这会把“你好”变成“你好”。做这件事的正确方法是什么?

最佳回答

一种解决方案可能是关闭php设置中的magic_quotes_gpc,或者另一种是在$_GET[“srq”]中使用条带斜线

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

我想你知道那有多没有保障吧?

问题回答
echo  value="  . htmlspecialchars($_GET[ srq ]) .  " 

并且不要自动添加斜线。如果需要在数据库中插入一些内容,请使用数据库转义函数对其进行转义(例如mysql的mysql_real_eescape_string()),而不是依赖斜杠。

你有神奇的引号=打开

使用get_magic_quotes_gpc检查它们是否打开,然后使用条带斜杠以删除引号





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签