Insert Html content in mysql

Codes here !

Moderators: macek, egami, gesf

lvidya
New php-forum User
New php-forum User
Posts: 37
Joined: Wed Jun 20, 2012 3:20 am

Insert Html content in mysql

Postby lvidya » Mon Aug 06, 2012 12:30 am

hai, how to insert html codes into database

Jeroen
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 10, 2012 4:37 pm
Contact:

Re: Insert Html content in mysql

Postby Jeroen » Sun Aug 12, 2012 8:22 pm

mysql_query("INSERT INTO `blabla` SET `bla` = '".$escapedHtmlCode."'");

NigelRen
php-forum Active User
php-forum Active User
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Insert Html content in mysql

Postby NigelRen » Sun Aug 12, 2012 11:36 pm

You don't need to do anything special about inserting html codes into a database as they simply consider the content as a list of characters.

So using something like ( copied and modified from http://www.w3schools.com/php/php_mysql_insert.asp )

Code: Select all

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age, Signature)
VALUES ('Peter', 'Griffin',35,'<b>Pete</b>)");

mysql_close($con);
?>

Would put the Pete in bold if simply including the signature in the html.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Google [Bot] and 1 guest