You are here: Re: Inserting PHP5 and HTML code into MySQL « All PHP « IT news, forums, messages
Re: Inserting PHP5 and HTML code into MySQL

Posted by Du on 10/31/05 02:18

you need to run addslashes before inserting your code into the database
(this will escape all the quote and control character in your code), and you
need run stripslashes after you retrieve the data from the database


http://ca.php.net/manual/en/function.addslashes.php
http://ca.php.net/manual/en/function.stripslashes.php



"Skylinux" <spam@network-technologies.org> wrote in message
news:_M69f.2152$2y.335@newsread2.news.atl.earthlink.net...
> I'm trying to use my database to store a lot of the redundant PHP and
> HTML code.
> Is there a special function I can use to insert the code into SQL, when
> I try it using the input of a <textarea> the insert fails.
>
> Here is a sample of what I would like to insert into a MySQL database.
> ######### code sample start
> <tbody>
> <tr>
> <td style="vertical-align: top;">
> <table style="width: 100%; text-align: left;" border="0"
> cellpadding="2" cellspacing="2">
> <tbody>
> <tr>
> <td style="vertical-align: top;">
> <?PHP
> //Modified to include options and different templates
> $Sec_run = $_POST['Sec_run'];
> $inc_dir = '/path/to/inc/';
> include $inc_dir.'menu-projects.inc'; //Include Menu
> ###### code sample end
>
>
> And here is an example of how I'm currently adding the <textarea> text
> into the database. It can insert plain text but no code.
>
> ########## PHP code insert example
> $db="nameofdb";
> //make mysql connection
> $conn = @mysql_connect("localhost","$db_un_admin","$db_admin") or
> die("Could not connect to MySQL server");
> //select specified database
> $rs = @mysql_select_db("$db", $conn) or die("Could not select database");
>
> $sql = "insert into $Cat_name(Cat_ID , Title , Article , User_ID ,
> Visible) values(\"$Cat_ID\", \"$Title\", \"$Article\", \"$User_ID\",
> \"$Visible\") ";
> //echo("<br>SQL: " . $sql . "<br><br"); //Debug
> $result = mysql_query( $sql,$conn) or die("Could not insert into table
> $Cat_name"); //Run query;
> ###########3 PHP code end
>
> Any ideas on how to get this done are very appreciated.
>
> Skylinux
>



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация