Current location: Hot Scripts Forums » Programming Languages » PHP » store php and html in mysql


store php and html in mysql

Reply
  #1 (permalink)  
Old 02-21-10, 08:33 AM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
Post store php and html in mysql

how do i properly store my php and html code in mysql ?

ok i have text area and i would paste my php and html code inside the text area and then insert it to table

i use this but the code ($content) is not display correctly when i call it other page

PHP Code:

<textarea rows='6' cols='40' name='content'></textarea
PHP Code:

 $content mysql_real_escape_string(htmlspecialchars($_POST['content'])); 

i have read about eval but did not really understand it


how to use it ?
let say i want to paste this

PHP Code:

<?php echo 'hello world<br>'?>

the code is change to
PHP Code:

<?php echo \'hello world<br>\'; ?>

in database

in browser it is display like this
Code:
\'; ?>
p/s :move this topic if this is not suitable here

Thank you in advance

Last edited by sarahmx; 02-21-10 at 08:41 AM.
Reply With Quote
  #2 (permalink)  
Old 02-21-10, 07:13 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Try storing just HTML, no PHP.

In you example above, it would be:

hello world<br>
Reply With Quote
  #3 (permalink)  
Old 02-21-10, 08:47 PM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
the hello world is just an example

the actual php code i want to paste is different...(a bit long)
Reply With Quote
  #4 (permalink)  
Old 02-22-10, 05:29 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I don't think storing PHP in the database is a good idea. If you want to extract it from the database, then execute it, you can use the eval function.

What are you trying to do?
Reply With Quote
  #5 (permalink)  
Old 02-22-10, 06:27 AM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
i don't know if this possible, what i'm trying to do with a help from a friend is a simple SEO content generation script... a page will pull data content from my database

we will input file name, page title, meta keywords/description and content (lot of text and some php coding) in admin side

and then automatically generate a php file based on the data from the database in a choosen web server folder with the $filename * php

i'm stuck with

1. how to add content (html & php) to the database
2. how to generate the file


what is the best way to do this...

any simple use of eval ?
Reply With Quote
  #6 (permalink)  
Old 02-22-10, 06:37 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Don't put PHP in the database. Store keywords in the database, and write them into the HTML when it's delivered.

PHP Code:

<?php

$s
='';
echo 
'<meta name="keywords" content="';
foreach (
$keywords as $k => $v)
  
$s.=$v.',';
$s=substr($s,0,-1);
echo 
$s.'" />';
?>
Not tested.

Don't spend too much time on keywords - the search engines rely more heavily on the site content.
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
sarahmx (02-22-10)
  #7 (permalink)  
Old 02-22-10, 10:20 AM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
Thank you wirehopper, got some idea to implement this

for html i use addslashes() to insert, stripslashes() to pull the data from database

for php i will put it in external file and just use include

i've learned a lot today......thanks :-)
Reply With Quote
  #8 (permalink)  
Old 02-22-10, 10:34 AM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
is it possible i would like if i click submit/save the form a file is generated/created automatically in server based on a template define and named with the name that i input for filename....
Reply With Quote
  #9 (permalink)  
Old 02-22-10, 02:06 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Are you building a CMS? If so - you might want to check some of the existing solutions - The CMS Matrix - cmsmatrix.org - The Content Management Comparison Tool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Required Sr. Software Engineers (PHP, MySQL) osscube Job Offers & Assistance 0 09-10-08 07:15 AM
For Hire (3 years exp.): Looking for Php, Mysql, AJAX, JavaScript, HTML, XML Barkat Job Offers & Assistance 1 09-25-07 04:15 PM
Generate HTML output with PHP and mySQL zoliky PHP 3 10-03-06 05:26 AM
PHP and Database HTML store NoMercy PHP 5 04-22-06 03:24 PM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 08:03 PM


All times are GMT -5. The time now is 08:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.