Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-02-2002, 09:59 AM   PM User | #1
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
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
Tidus is offline   Reply With Quote
Old 10-02-2002, 10:59 AM   PM User | #2
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 10-02-2002, 11:11 AM   PM User | #3
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
Hi - I'm a newbie..

Bit confused now

Any more help?
Tidus is offline   Reply With Quote
Old 10-02-2002, 11:47 AM   PM User | #4
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 10-02-2002, 11:50 AM   PM User | #5
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
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!
Tidus is offline   Reply With Quote
Old 10-02-2002, 11:58 AM   PM User | #6
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 10-02-2002, 12:00 PM   PM User | #7
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
is there anyway it can be done?
Tidus is offline   Reply With Quote
Old 10-02-2002, 12:23 PM   PM User | #8
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 10-02-2002, 12:24 PM   PM User | #9
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
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
Tidus is offline   Reply With Quote
Old 10-02-2002, 12:30 PM   PM User | #10
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
Can You post the PHP code, and at least one of the texts as stored in the database?

Alex
Alekz is offline   Reply With Quote
Old 10-02-2002, 12:34 PM   PM User | #11
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
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!
Tidus is offline   Reply With Quote
Old 10-02-2002, 12:56 PM   PM User | #12
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 10-02-2002, 12:57 PM   PM User | #13
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
i have done that

it just comes up with $id then!
Tidus is offline   Reply With Quote
Old 10-02-2002, 01:12 PM   PM User | #14
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 10-02-2002, 01:15 PM   PM User | #15
Tidus
New Coder

 
Join Date: Aug 2002
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
Tidus is an unknown quantity at this point
this is what i get.

http://www.handclaireonline.com/boo.php3
Tidus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:26 AM.


Advertisement
Log in to turn off these ads.