无法将内容插入数据库,需要帮助转义PHP代码[重复]

时间:2021-03-22 02:06:44

Possible Duplicate:
Difference between single quote and double quote string in php

可能重复:php中单引号和双引号字符串之间的差异

Hey I'm having trouble inserting page content into my database.

嘿,我在将页面内容插入数据库时​​遇到问题。

I'm trying to store:

我正试图存储:

<p class=\"heading_large\"><?php echo $Topic2C2A[data]; ?></p>

Using this code:

使用此代码:

$sql="UPDATE event SET 
  data='<p class=\"heading_large\"><?php echo $Topic2C2A[data]; ?></p>' 
  WHERE id='2'";

But when I look at the table all I see is:

但当我看到桌子时,我看到的是:

<p class="heading_large"><?php echo ; ?></p>

I've obviously escaped the HTML with slashes, is there something similar I need to do with the PHP so $Topic2C2A[data] is displayed?

我显然已经使用斜杠转义了HTML,是否有类似我需要用PHP做的事情,所以显示了$ Topic2C2A [数据]?

3 个解决方案

#1


0  

I would suggest you write your $sql as:

我建议你写你的$ sql为:

$sql="UPDATE event SET data='<p class=\"heading_large\">".$Topic2C2A[data]."</p>' WHERE id='2'";

#2


0  

Your issue is related to the fact PHP is processing variables inside " (double) quotes.

您的问题与PHP在“(双)引号内处理变量的事实有关。

You can change quotes to ' (single) or another option is to change $Topic2C2A[data] to \$Topic2C2A[data].

您可以将引号更改为'(单个)或另一个选项是将$ Topic2C2A [data]更改为\ $ Topic2C2A [data]。

#3


0  

Did you try mysqli_real_escape_string()? It should return a fully escaped String!

你试过mysqli_real_escape_string()吗?它应该返回一个完全转义的字符串!

#1


0  

I would suggest you write your $sql as:

我建议你写你的$ sql为:

$sql="UPDATE event SET data='<p class=\"heading_large\">".$Topic2C2A[data]."</p>' WHERE id='2'";

#2


0  

Your issue is related to the fact PHP is processing variables inside " (double) quotes.

您的问题与PHP在“(双)引号内处理变量的事实有关。

You can change quotes to ' (single) or another option is to change $Topic2C2A[data] to \$Topic2C2A[data].

您可以将引号更改为'(单个)或另一个选项是将$ Topic2C2A [data]更改为\ $ Topic2C2A [data]。

#3


0  

Did you try mysqli_real_escape_string()? It should return a fully escaped String!

你试过mysqli_real_escape_string()吗?它应该返回一个完全转义的字符串!