SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Running PHP from a database

    Hi All

    I am storing some PHP code in my database however when it is retreaved it is not being run as PHP.

    There there fix or a way around this?

    Thanks

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to use eval() so that it is run as PHP.

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How does that work?

    This is the code in the database:

    PHP Code:
    depot-location.php?PageID=contact-us&AID=<?php echo("$AID"); ?>&locid=<?php echo("$id"); ?>
    Thanks for your help

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Czech Rep.
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrmbarnes
    How does that work?

    This is the code in the database:

    PHP Code:
    depot-location.php?PageID=contact-us&AID=<?php echo("$AID"); ?>&locid=<?php echo("$id"); ?>
    Thanks for your help
    has to work like this:

    PHP Code:
    $var = 'echo "depot-location.php?PageID=contact-us&AID=<?php echo(\"$AID\");?>&locid=<?php echo(\"$id\"); ?>";';

    eval($var);
    http://ua2.php.net/manual/en/function.eval.php
    Free domain tools: WebBoar - sniffing out domain secrets.

  5. #5
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK

    I have been playing with this and sort of have it working.

    If I add the PHP code to the variable it works fine, however, if I pull the PHP code from the database it doesn't work.

    Here is what I'm doing:

    PHP Code:
    $PageID $_GET['PageID'];
    $id $_GET['locid'];
    $AID $_GET['AID'];

    $content mysql_query"
    SELECT 
    PageID,
    pagecontent
    FROM 
    Content
    WHERE PageID=
    $PageID");

    $content mysql_fetch_array($content);
    $pagecontent $content['pagecontent']; 
    This part works fine. Now the eval() bit:

    PHP Code:
    $name "$pagecontent";
    $str '$name';
    eval(
    "\$str = \"$str\";");
    echo 
    $str"\n"
    This pulls in all the inforamtion but does not run the php code in my link: depot-location.php?PageID=contact-us&AID=$AID&locid=$id.

    If I do this:

    PHP Code:
    $name "depot-location.php?PageID=contact-us&AID=$AID&locid=$id";
    $str '$name';
    eval(
    "\$str = \"$str\";");
    echo 
    $str"\n"
    The PHP code runs fine however I don't have the rest of the content and nothing is coming from the database.

    Any ideas?

  6. #6
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone help me with this PLEASE.
    Last edited by mrmbarnes; Apr 2, 2004 at 05:48.


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
  •