Re: Inserting PHP5 and HTML code into MySQL



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@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:_M69f.2152$2y.335@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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 =----
.



Relevant Pages

  • Re: Continuously monitors Outlook and stores email data in database.
    ... automatically for an e-commerce web site. ... along with some HTML pages I created to allow customers to log in, ... information and put it into your database. ... any testing of any illustrative code sample for any particular use. ...
    (comp.databases.ms-access)
  • Re: templates question: can you parameterize the template passed?
    ... Would you mind posting a little code sample. ... > The action class does not need to derive from the accessor. ... >> But I want a general database class, ... >> Angus Comber ...
    (microsoft.public.vc.atl)
  • Re: connectionstring for VB.Net app which connects to MDB on website
    ... I am hoping that someone can provide a code sample using the following ... sample information below. ... is run on a local computer and connects to our database on our website. ... The alternative is to use a Web Service or binary Web Remoting. ...
    (microsoft.public.dotnet.general)
  • Re: upload file into database in asp
    ... Do you have a code sample of how you run the doc file download/edit/upload? ... so far I am doing some small testings and what I can do is upload the ... however, I cann't insert them into the database, Plus, what type ... without even the implied warranty of merchantability ...
    (microsoft.public.inetserver.asp.general)
  • Re: connectionstring for VB.Net app which connects to MDB on website
    ... > I am hoping that someone can provide a code sample using the following ... > sample information below. ... > is run on a local computer and connects to our database on our website. ...
    (microsoft.public.dotnet.general)