php – 将html代码插入到mysql表中

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 将html代码插入到mysql表中脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用joomla管理一个网站…我正在开发一个独立的PHP应用程序,将插入和修改数据到Joomla使用的表来存储其动态创建的网页的 HTML

它的工作原理是我使用joomla组件来创建内容,这些文章HTML代码被存储在表中的一个字段(如content_table)中,由joomla ..这个HTML代码稍后被检索以构造一个网页的一部分.

我想对我的独立应用程序做同样的事情,即将HTML代码添加到content_table中,后来可以由joomla检索以构建页面的一部分.

问题是:HTML代码当然有很多单引号和双引号,这在插入到数据库中造成了一个问题.我尝试过MysqL_escape_string()并仍然得到语法错误.

我可以使用addslashes(),但是由于joomla本身稍后检索该代码,所以在稍后检索它时不可能使用stripslashes().

有没有反正我可以添加HTML代码表的字段…

谢谢你的建议…

编辑:添加MysqL_escape_string()后我得到

Error adding details. Reason : You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'fulltext = '\n

这是我的查询

UPDATE $jos_content
SET    introtext = '$intro_code',fulltext  = '$article_code'
WHERE  id = '$article_id'";

输入字符串如下:

$article_code = '<hr id="system-readmore" />
<center>{loadposition user50}</center>
<p style="text-align: center;">
<span style="color: rgb(0,255,255);">
<i>
<b>
<span style="font-size: x-large;">
<span style="font-family: Arial;">
&nbsp;
</span>
</span>
</b>
</i>
</span>
<span style="color: rgb(0,255);">
<i>
<b>
<span style="font-size: x-large;">
<span style="font-family: Arial;">
<?PHP echo $title; ?>
</span>
</span>
</b>
</i>
</span>
<span style="color: rgb(0,255);">
<i>
<b>
<span style="font-size: x-large;">
<span style="font-family: Arial;">
<br />
</span>
</span>
</b>
</i>
</span>
</p>
<p style="text-align: center;">
<img height="269" width="515" border="3" 
title="<?PHP echo $title; ?>" 
alt=" <?PHP echo $title; ?>"
src="<?PHP echo $article_image;?>"
</p> 
<p>
<span style="font-size: small;">
<span style="font-family: Arial;">
<span style="color: rgb(153,204,255);">
<p style="margin-top: 2px; margin-bottom: 2px; margin-left: 120px; text-align: left;">
<i> 
<span style="color: rgb(0,0);"> 
<strong>
Cast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :
</strong>
<b>
</b>
</span>
</i>
<span style="color: rgb(0,255);">
<b>
<?PHP echo $cast; ?>
</b>
</span>
<i>
<span style="color: rgb(0,255);">
<b>
<br />
</b>
</span>
</i>
<span style="font-family: Arial;">
<span style="font-size: small;">
<span style="color: rgb(153,255);">
</span>
</span>
<span style="color: rgb(0,0);">
<i>
<strong>
Direction&nbsp;&nbsp;&nbsp;
</strong>
</i>
<strong>
:
</strong>
<b>
</b>
</span>
<span style="color: rgb(0,255);">
<b>
<span class="href"
id="ctl00_ContentPlaceHolderMainContent_FormView1_Director">
<?PHP echo $director; ?>
</span>
</b>
</span>
</span>
<span style="font-family: Arial;">
<br />
<span style="color: rgb(0,0);">
<i>
<strong>
Production
</strong>
</i>
<strong>
:
</strong>
<b>
</b>
</span>
<span style="color: rgb(0,255);">
<b>
<?PHP echo $direction; ?>
</b>
</span>
<span style="color: rgb(255,102,0);">
<i>
<b>
<br />
</b>
</i>
</span>
<span style="font-family: Arial;">
<span style="color: rgb(0,0);">
<span style="font-family: Arial;">
<span style="font-size: small;">
<i>
<strong>
Music&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</strong>
</i>
<strong>
:
</strong>
</span>
</span>
</span>
</span>
<span style="color: rgb(0,255);">
<b>
<i>
</i>
<?PHP echo $music; ?>
<i>
<br />
<span style="color: rgb(0,0);">
Lyrics&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</i>
<span style="color: rgb(0,0);">
:
</span>
<i>
</i>
</b>
</span>
<span style="color: rgb(0,255);">
<b>
<?PHP echo $lyrics; ?>
</b>
</span>
<span style="color: rgb(0,255);">
<b>
<i>
<br />
</i>
<span style="color: rgb(0,0);">
<i>
Year&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</i>
:
</span>
<?PHP echo $year; ?>
</b>
</span>
</span>
<i>
<span style="color: rgb(0,255);">
<b>
</b>
</span>
</i>
</p>
</span>
</span>
</span>
</p>
<p>
<left>
{loadposition user14}
&nbsp;
</left>
</p>
<div style="text-align: center;">
<p>
<i>
<span style="font-family: Arial;">
<b>
<span style="font-size: medium;">
<span style="color: rgb(51,255);">
Click
<img src="images/stories/Play button1.png"
alt="alt" />
in the Playlist to Download Songs
</span>
</span>
</b>
</span>
</i>
</p>
</div>
<table border="0" align="center">
<tbody>
<tr>
<td>
<h4 style="text-align: center;">
<i>
<span style="color: rgb(102,0);">
<b>
<b>
&nbsp;High Bandwidth Users
</b>
</b>
</span>
</i>
<i>
<span style="color: rgb(102,0);">
<b>
<b>
&nbsp;
</b>
</b>
</span>
</i>
<span style="color: rgb(102,0);">
<b>
</b>
</span>
</h4>
</td>
<td>
<h4 style="text-align: center;">
<i>
<span style="color: rgb(102,0);">
<b>
<b>
&nbsp;Low Bandwidth Users
</b>
</b>
</span>
</i>
<span style="color: rgb(102,0);">
<b>
<br />
</b>
</span>
</h4>
</td>
</tr>
<tr>
<td>
{auto width=&quot;235&quot; displayheight=&quot;0&quot; height=&quot;225&quot;} <?PHP echo $hqList; ?> {/auto}
</td>
<td>
{auto width=&quot;235&quot; displayheight=&quot;0&quot; height=&quot;225&quot;}<?PHP echo $lqList; ?>{/auto}
</td>
</tr>
</tbody>
</table>
<center>
{loadposition user50}
</center>';
我更喜欢在插入数据库之前将代码转换成普通字符串.我认为这是最安全的方案.考虑使用这段代码
$article_code = base64_encode($article_code);
/* insert to database */

所以,当你想要使用该代码时,只需使用base64_decode进行解码.我建议你使用’text’数据类型来保存$article_code而不是’varchar’.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 将html代码插入到mysql表中全部内容,希望文章能够帮你解决php – 将html代码插入到mysql表中所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: