Results 1 to 6 of 6

Thread: store php and html in mysql

  1. #1
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question store php and html in mysql

    Hi,

    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 is not displaying correctly when i call it

    PHP Code:
    <textarea rows='6' cols='40' name='content'></textarea
    PHP Code:
     $content mysql_real_escape_string(htmlspecialchars($_POST['content'])); 
    let say i want to paste this..

    PHP Code:
    <?php echo 'hello world<br>'?>
    this is just an example..the actual code that i want to paste is a bit long

    the code is change to
    PHP Code:
    <?php echo \'hello world<br>\'; ?>
    in database

    in browser it is display like this
    Code:
    \'; ?>
    Help !!

    Thank you in advance

  2. #2
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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 ?

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    html is easy (just addslashes() to insert, stripslashes() when you pull it out). php is more complicated. There is a function called serialize() that will convert your php into a storable string, then you would unserialize() it when you pull it back out. But it's still just a string; so you'd have to use eval() to parse it as php code (which can be a security risk if you're dealing with user-submitted content in any way).

    php code is *much* easier to store in an external file. Take whatever chunk of code you want to store and just put it in a separate file and include() it whenever you need.

    As for generating the file, it sounds to me like you're trying to create a php template. For example, your template would look like:
    template.php
    PHP Code:
    <html>
      <head>
        <title><?php echo $title?>
      </head>
      <body>
        <h1 id="header">Welcome to my site</h1>
        <div id="welcome"><h2><?php echo $title?></h2>
          <?php echo $welcomeArticle?>
        </div>
      </body>
    </html>
    and you would define the content like so:
    webpage.php
    PHP Code:
    <?php
    $title 
    "Page title";
    $welcomeArticle "Hello world, welcome to my website's home page!";
    include(
    "/path/to/template.php");
    ?>

  4. The Following User Says Thank You to traq For This Useful Post:

    sarahmx (02-22-2010)

  5. #4
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thanks traq, you gave me a clear idea on how to implement this..

  6. #5
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    As for generating the file, it sounds to me like you're trying to create a php template.
    Yes something like that...

    is it possible i would like if i click submit/save the form a file is generated/created automatically in server based on the template define and named with the name that i input for $filename....

  7. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    so...

    you want to input title/content/etc. into a form on a webpage
    have the script generate a page, based on the template, using your info
    ?

    do you want the page to be saved on the server (so anyone can visit it) or do you just want the page to be generated and served to you (gone after you leave)?

    the answer is yes, either way. Saving the file to your server will be more complicated, you'll have to fix write permissions, etc., and I would *definitely* add security measures - otherwise, anyone could write anything they like to your website. Read up on php filesystem functions.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •