Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question help with php in included files?

    Hello.

    I am currently writing a large news database.

    It allows us to fill in a form on a website and then it saves the info to the database.

    Anyway - when we actually try and put php tags into the news items we store in the database, they dont show up on the page that displays it.

    But, if you go to view source, they are written in there? Can anybody help.

    James

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I think i wont work that way... Storing PHP code mixed with free text in a database, then extract the text in a string variable and get PHP code parsed...
    I've done something similar, but used custom tags like [ArticleID] included in text, then replaced them with the appropriate value... But there was a limited set of recognized tags and there was specific code that maked the replacement for each tag...

    Alex

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi - I'm a newbie..

    Bit confused now

    Any more help?

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, that was just a shot in the dark...
    Can You post some sample or more detailed explanation of what You want to do and what goes wrong?

    Alex

  • #5
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Well - I have a page


    display.php3 - this file includes a file news.php3

    - which gets stuff from the database - that works fine.

    But when i store php tags into the database, they dont show up in news.php3. if you view the source of the page, they are there in full. they dont show up on the broswer window..

    i have tried everything and i just cant get it right!

  • #6
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK,
    PHP tags stored in a database will not be executed by the server, because they are not part of any script - they are just string constants. Browser will not show them, because by default it will skip any tag it does not understand, as <?...?> for example.
    Now, are You sure storing PHP code in the database can not be avoided? I just can not image any reason for the code to be there...

    Alex

  • #7
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    is there anyway it can be done?

  • #8
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure, but that does not make sense...
    1. Extract the text from database in a variable
    2. Use a regular expression to match all <?...?> pairs.
    3. Parse the text inside and replace all that is a syntactically valid PHP variable with the appropriate value.
    4. Output the result to the browser.

    Alex

  • #9
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    umm sorry to do this - but would u mind just givin me an example of those steps?

    i dont quite know what u mean. sorry

  • #10
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can You post the PHP code, and at least one of the texts as stored in the database?

    Alex

  • #11
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ok.

    This is the code on the news.php3 page.

    PHP Code:
     <?php

        $db 
    mysql_connect("www.handclaireonline.com""connect

        mysql_select_db("
    news",$db)or die(mysql_error());

        $sql = "
    SELECT FROM newsdb WHERE $id=id";

        $result = mysql_query($sql);

        $myrow = mysql_fetch_array($result);

        $id = $myrow["
    id"];

        $displaytitle = $myrow["
    displaytitle"];

        $news = $myrow["
    news"];

        $displaydate = $myrow["
    displaydate"];

        $time = $myrow["
    time"];

        $by = $myrow["
    by"];
        
        $realtitle = $myrow["
    realtitle"];
        
        $dateyear = $myrow["
    dateyear"];
        
    $newsshort = substr($news, 0, 250);

        ?>

    <body topmargin="
    0" leftmargin="0">
    <p style="
    margin-top0margin-bottom0">
     <font face="
    Verdana" size="1" color="#404D55">
     
     
    <?php
     
     
    if ($archive) {
     
     echo 
    "<br><font face='Verdana' size=2 color=#FDCD0F>[ <a href=http://www.handclaireonline.com/archive/archive.php3?news=yes><font face='Verdana' size=2 color=#FDCD0F>return to archive</a> ]</font><p>";

    }

    ?>
            <br><font face=Verdana size=1 color=#404D55>
            //<?php echo $displaydate ?>-<?php echo $dateyear ?><br>
    </font><b>
    <font face="Verdana" size="2" color="#FFFFFF"><?php echo $realtitle ?><br>
     <br>
     </font></b>
             <font face="Verdana" size="1" color="#FDCD0F"><?php echo $news ?><br>
             &nbsp;</font><p style="margin-top: 0; margin-bottom: 0">
    <img border="0" src="linehoriz.jpg" width="522" height="5"><br>
    <br>
    <b>
    <font color="#FFFFFF" face="Verdana" size="2"><a href="display.php3">
    <font color="#FFFFFF">[click here to go back]</font></a></font></b></p>
    and this is the text from one of the database - it only has one small amount of php - so i just post that area.

    PHP Code:

     <br>
        This seems like a pretty much all ballad cd - but there will be some upbeat 
        tracks as well! More news when we get it!<br>
    You can check out some more news about the album <a href="display.php3?id=50&ref=<?php echo $id ?>">here </a>
    hope this helps

    thanks!

  • #12
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I see...
    Try just to change the part of code that stores all this in the database so that it sotores $id instead of <?php echo $id ?>.
    PHP will replace it with its value authomatically...

    Alex

  • #13
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i have done that

    it just comes up with $id then!

  • #14
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm,
    It should not...
    What version of PHP are You using?
    There's a piece of PHP code. Can You start it in Your environement and tell me what's the output?
    <?
    $id = 5;
    $Str = "<br>This seems like a pretty much all ballad cd - but there will be some upbeat tracks as well! More news when we get it!<br>You can check out some more news about the album <a href=\"display.php3?id=50&ref=$id\">here </a>";

    print($Str);

    ?>

    Alex

  • #15
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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