在mysql表格中插入html代码 [英] Inserting html code in a mysql table

查看:92
本文介绍了在mysql表格中插入html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用joomla来管理一个网站......我正在开发一个独立的php应用程序,它会将数据插入和修改到joomla使用的表中,以存储它动态创建的网页的html ...



它的工作方式是使用joomla组件创建内容,并且这些文章的html代码存储在表中的字段中,称为joomla的content_table。这个HTML代码后来被检索到构建网页的一部分。



我想对我的独立应用程序做同样的事情......即将html代码添加到字段在content_table中,以后可以通过joomla检索来构造页面的一部分。



问题是:html代码当然有很多单和双引号,这在插入数据库时​​会造成问题..我尝试过mysql_escape_string(),但仍然出现语法错误..

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

是否有我可以将html代码添加到表格的字段中......



感谢您的建议... !!
$ b

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

 添加详细信息时出错。原因:您的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以在'fulltext ='\\\



附近使用正确的语法

这是我的查询:

  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,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,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 =269width =515border =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;>
< p style =margin-top:2px; margin-bottom:2px; margin-left:120px; text-align:left;>
< i>
< strong>
演员& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;     :
< / strong>
< b>
< / b>
< / span>
< / i>
< span style =color:rgb(0,255,255);>
< b>
<?php echo $ cast; ?>
< / b>
< / span>
< i>
< span style =color:rgb(0,255,255);>
< b>
< br />
< / b>
< / span>
< / i>
< span style =font-family:Arial;>
< span style =font-size:small;>
< / span>
< / span>
< i>
< strong>
方向& nbsp;& nbsp;& nbsp;
< / strong>
< / i>
< strong>

< / strong>
< b>
< / b>
< / span>
< span style =color:rgb(0,255,255);>
< b>
< span class =href
id =ctl00_ContentPlaceHolderMainContent_FormView1_Director>
<?php echo $ director; ?>
< / span>
< / b>
< / span>
< / span>
< span style =font-family:Arial;>
< br />
< i>
< strong>
制作
< / strong>
< / i>
< strong>

< / strong>
< b>
< / b>
< / span>
< span style =color:rgb(0,255,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 =font-family:Arial;>
< span style =font-size:small;>
< i>
< strong>
音乐& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;
< / strong>
< / i>
< strong>

< / strong>
< / span>
< / span>
< / span>
< / span>
< span style =color:rgb(0,255,255);>
< b>
< i>
< / i>
<?php echo $ music; ?>
< i>
< br />
歌词& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;
< / span>
< / i>

< / span>
< i>
< / i>
< / b>
< / span>
< span style =color:rgb(0,255,255);>
< b>
<?php echo $ lyrics; ?>
< / b>
< / span>
< span style =color:rgb(0,255,255);>
< b>
< i>
< br />
< / i>
< i>
年份& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;     
< / i>

< / span>
<?php echo $ year; ?>
< / b>
< / span>
< / span>
< i>
< span style =color:rgb(0,255,255);>
< b>
< / b>
< / span>
< / i>
< / p>
< / span>
< / span>
< / span>
< / p>
< p>
< left>
{加载位置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,255);>
点击
< img src =images / stories / Play button1.png
alt =alt/>
在播放列表中下载歌曲

< / span>
< / b>
< / span>
< / i>
< / p>
< / div>
< table border =0align =center>
< tbody>
< tr>
< td>
< h4 style =text-align:center;>
< i>
< b>
< b>
& nbsp;高带宽用户
< / b>
< / b>
< / span>
< / i>
< i>
< b>
< b>
& nbsp;
< / b>
< / b>
< / span>
< / i>
< b>
< / b>
< / span>
< / h4>
< / td>
< td>
< h4 style =text-align:center;>
< i>
< b>
< b>
& nbsp;低带宽用户
< / b>
< / b>
< / span>
< / i>
< b>
< br />
< / b>
< / span>
< / h4>
< / td>
< / tr>
< tr>
< td>
{auto width =& quot; 235& quot; displayheight =安培; QUOT 0安培; QUOT; height =& 225& quot;}<?php echo $ hqList; ?> {/ auto}
< / td>
< td>
{auto width =& quot; 235& quot; displayheight =安培; QUOT 0安培; QUOT; height =& 225& quot;}<?php echo $ lqList; ?> {/ auto}
< / td>
< / tr>
< / tbody>
< / table>
< center>
{加载位置user50}
< / center>';


解决方案

毕竟不是逃避函数......



查看查询:

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

你可以看到'fulltext'字段...显然,单词fulltext是一个mysql关键字...为了确切,它是像TEXT,INT,MEDIUMTEXT等字段类型...

我将查询改为这个

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

瞧... ... !!!!


I use joomla to manage a website... and i am developing a stand alone php application that will insert and modify data into the tables that are used by joomla to store the html of webpages that it dynamically creates...

The way it works is i use a joomla component to create content and the html code of these articles are stored in a field in a table, say content_table, by joomla.. This html code is later retrieved to construct a part of a webpage.

I want to do the same with my standalone app... i.e add the html code to the filed in content_table which can later be retrieved by joomla to construct the part of the page.

The problem is : The html code,naturally, of course, has a lot of single and double quotes and this pose a problem while inserting into the database.. I've tried mysql_escape_string() and still get syntax errors..

I can use addslashes() but since joomla itself retrieves the code later, it is not possible to use stripslashes() while retrieving it later....

Is there anyway i can add the html code the table's field...

Thanks for your suggestions...!!

Edit : After adding mysql_escape_string() i get

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

This is my query :

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

The input string is as follows :

 $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, 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, 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, 255, 0);"> 
<strong>
Cast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :
</strong>
<b>
</b>
</span>
</i>
<span style="color: rgb(0, 255, 255);">
<b>
<?php echo $cast; ?>
</b>
</span>
<i>
<span style="color: rgb(0, 255, 255);">
<b>
<br />
</b>
</span>
</i>
<span style="font-family: Arial;">
<span style="font-size: small;">
<span style="color: rgb(153, 204, 255);">
</span>
</span>
<span style="color: rgb(0, 255, 0);">
<i>
<strong>
Direction&nbsp;&nbsp;&nbsp;
</strong>
</i>
<strong>
:
</strong>
<b>
</b>
</span>
<span style="color: rgb(0, 255, 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, 255, 0);">
<i>
<strong>
Production
</strong>
</i>
<strong>
:
</strong>
<b>
</b>
</span>
<span style="color: rgb(0, 255, 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, 255, 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, 255);">
<b>
<i>
</i>
<?php echo $music; ?>
<i>
<br />
<span style="color: rgb(0, 255, 0);">
Lyrics&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</i>
<span style="color: rgb(0, 255, 0);">
:
</span>
<i>
</i>
</b>
</span>
<span style="color: rgb(0, 255, 255);">
<b>
<?php echo $lyrics; ?>
</b>
</span>
<span style="color: rgb(0, 255, 255);">
<b>
<i>
<br />
</i>
<span style="color: rgb(0, 255, 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, 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, 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, 255, 0);">
<b>
<b>
&nbsp;High Bandwidth Users
</b>
</b>
</span>
</i>
<i>
<span style="color: rgb(102, 255, 0);">
<b>
<b>
&nbsp;
</b>
</b>
</span>
</i>
<span style="color: rgb(102, 255, 0);">
<b>
</b>
</span>
</h4>
</td>
<td>
<h4 style="text-align: center;">
<i>
<span style="color: rgb(102, 255, 0);">
<b>
<b>
&nbsp;Low Bandwidth Users
</b>
</b>
</span>
</i>
<span style="color: rgb(102, 255, 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>';

解决方案

Well..Debugged it.. Turns out the problem was after all not with the escaping function...

Check out the query :

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

You can see the 'fulltext' field... Apparently, the word "fulltext" is a mysql keyword... To be precise,it's a field type like TEXT, INT, MEDIUMTEXT etc...

I changed the query to this

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

And voila...!!!!

这篇关于在mysql表格中插入html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆