2012-04-05 80 views
0

我试图为工作提供一个编辑器。它必须具有预览功能。有2种形式。第一个表单提交预览,第二个表单预览时出现,并发送变量将它们保存在数据库中。问题是,当提交第二个表单时,所有引号都消失了。我尝试了mysql_real_escape_string,htmlspecialchars,htmlentitles,但没有任何工作。你知道问题出在哪里吗? 难道是因为我用变量'$ content'来存储网站的内容,而不是直接用'echo'输出吗? 谢谢!PHP - 使用包含引号的变量输入隐藏字段

<td><input style='float:left;' type='submit' name='jobpreview' value='preview' /> 
</form>"; 
if(isset($_GET['preview'])) 
{ 
$_POST['titel'] = htmlentities($_POST['titel']); 
$_POST['elm1'] = htmlentities($_POST['elm1']); 
    $content .= " <td><form action='?s=intern&sub=neuerjob&preview' method='POST'> 
    <input type='hidden' name='titel' value='".$_POST['titel']."' /> 
    <input type='hidden' name='elm1' value='".$_POST['elm1']."' /> 
    <input style='float:left;' type='submit' name='jobsave' value='save' /> 
    </form></td></tr></table>"; 
} 
+0

请勿使用htmlentities函数。 – hjpotter92 2012-04-05 21:05:22

回答

3

您需要使用second parameter to htmlentities()来对引号进行编码。

$titel = htmlentities($_POST['titel'], ENT_QUOTES); 
$elm1 = htmlentities($_POST['elm1'], ENT_QUOTES); 

<input type='hidden' name='titel' value='".$titel."' /> 
<input type='hidden' name='elm1' value='".$elm1."' /> 

为此,htmlentities()是矫枉过正虽然,你可以使用htmlspecialchars() 也与ENT_QUOTES PARAM。

$titel = htmlspecialchars($_POST['titel'], ENT_QUOTES); 
$elm1 = htmlspecialchars($_POST['elm1'], ENT_QUOTES); 
+0

对,工作。非常感谢你!! – Crayl 2012-04-05 21:10:16