Current location: Hot Scripts Forums » Programming Languages » PHP » Display PHP in HTML page using JS


Display PHP in HTML page using JS

Reply
  #1 (permalink)  
Old 04-24-06, 05:02 PM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
Display PHP in HTML page using JS

Now I have a problem, I want to be able to show the output of a php file on an html page. Now I always thought it was impossible to send proccessed php to an html document.

Now I see many people use free scripts to go on there html pages. for example here is sum code that bravenet uses to put on your site:

Code:
<script type="text/javascript" src="http://www.bravenet.com/cserv.php?pid=4&amp;tid=4&amp;afilid=1708443541"></script>
Now there they use sum JS code but have it pointing to a .php page. So does that mean you can process php on another website and then display it on a html page? Now I do a lot of php coding but what ever I tired I couldnt not get any information to be displayed on the html page using this method.

Is there some special code I need to put in my php file? If some one could point me in the right direction to where I could find out, or even tell me, I would be very greatful.
Reply With Quote
  #2 (permalink)  
Old 04-24-06, 05:21 PM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
I found this:

http://www.sitepoint.com/article/create-content-feed/2

I would be very happy to do my php scripts like this to be included into html but the matter of fact is, is that I just get a blank page. It just wont work.

Even if i make a simple script of my own that just document writes hello it doesnt show.

Anyone know why this aint working?
Reply With Quote
  #3 (permalink)  
Old 04-24-06, 05:23 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Does your server support PHP? If you view the source of the PHP page what does it say?
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Reply With Quote
  #4 (permalink)  
Old 04-24-06, 05:33 PM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
yes my server does support php.

http://www.steezmatic-designs.com/feed.php
http://www.steezmatic-designs.com/test.html

are the 2 files from that site. the test.html should display:

Couldn't load news

as there is no db set up. but instead it just shows as blank
Reply With Quote
  #5 (permalink)  
Old 04-24-06, 08:24 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
This:
Code:
<script language="JavaScript" type="text/js" src="feed.php"></script>
Should be:
Code:
<script language="JavaScript" type="text/JavaScript" src="feed.php"></script>
But the problem is
Quote:
<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home2/steez/public_html/feed.php</b> on line <b>44</b><br />
When I remove it, it does write the HTML code. So the problem is the MySQL query is failing for some reason.
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Reply With Quote
  #6 (permalink)  
Old 05-18-06, 12:13 PM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
Ive got all the above problem working now and now I just have a question on a script ive made:

Code:
<script language="JavaScript" type="text/JavaScript" src="http://www.website-codes.com/scripts/commentbox.php?style=1&id=1"></script>
and in the file commentbox.php is the following:

Code:
<?php
header("Content-Type: text/javascript");
if($style == 1) {
	include("style/cborange.html");
}
if($style == 2) {
	include("style/cbblue.html");
}
?>

document.write('<form action="http://www.website-codes.com/modules.php?name=Comment_Box&op=recieve" method="post" name="comment">');
document.write('<table width="100" border="1" cellspacing="0" cellpadding="0"><tr>');
document.write('<td bgcolor="#E0E0E0"><center>');
document.write('<table width="100" border="0" cellpadding="0" cellspacing="0">');
document.write('<tr><td>');
document.write('<font class="cbwc"><center><b>Send a comment</b></center><br />Name:</font>');
document.write('</td></tr><tr><td>');
document.write('<input name="name1" type="text" maxlength="100" class="cbwc">');
document.write('</td></tr><tr><td>');
document.write('<font class="cbwc">Email:</font>');
document.write('</td></tr><tr><td>');
document.write('<input name="emailsend" type="text" maxlength="200" class="cbwc">');
document.write('</td></tr><tr><td>');
document.write('<font class="cbwc">Comment:</font>');
document.write('</td></tr><tr><td>');
document.write('<input name="comment" type="text" maxlength="100" class="cbwc">');
document.write('</td></tr><tr><td>');
document.write('<input name="id" type="hidden" value="<?=$id ?>">');
document.write('</td></tr><tr><td>');
document.write('<center><input type="submit" name="Submit" value="Submit" class="cbwc"></center>');
document.write('</td></tr></table><br />');
document.write('<font class="cbwc">Comment box by</font><br>');
document.write('<a href="http://www.website-codes.com" class="cbwc">Website Codes</a></center></td></tr></table></form>');
now if you go to the file directly:

http://www.website-codes.com/scripts/commentbox.php

it tries to download it. How can I make my script maybe say a message instead saying an error message or redirect to the homepage. Basically stopping ppl access it directly
Reply With Quote
  #7 (permalink)  
Old 05-18-06, 12:25 PM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
NVM I've got it. I dont know why i didnt work when i tried this before:

Code:
<?php
if (eregi("http://www.website-codes.com/scripts/", $_SERVER['HTTP_REFERER'])) {
echo "no go area";
} else {
	header("Content-Type: text/javascript");
	
	if($style == 1) {
		include("style/cborange.html");
	}
	if($style == 2) {
		include("style/cbblue.html");
	}
	?>
	
	document.write('<form action="http://www.website-codes.com/modules.php?name=Comment_Box&op=recieve" method="post" name="comment">');
	document.write('<table width="100" border="1" cellspacing="0" cellpadding="0"><tr>');
	document.write('<td bgcolor="#E0E0E0"><center>');
	document.write('<table width="100" border="0" cellpadding="0" cellspacing="0">');
	document.write('<tr><td>');
	document.write('<font class="cbwc"><center><b>Send a comment</b></center><br />Name:</font>');
	document.write('</td></tr><tr><td>');
	document.write('<input name="name1" type="text" maxlength="100" class="cbwc">');
	document.write('</td></tr><tr><td>');
	document.write('<font class="cbwc">Email:</font>');
	document.write('</td></tr><tr><td>');
	document.write('<input name="emailsend" type="text" maxlength="200" class="cbwc">');
	document.write('</td></tr><tr><td>');
	document.write('<font class="cbwc">Comment:</font>');
	document.write('</td></tr><tr><td>');
	document.write('<input name="comment" type="text" maxlength="100" class="cbwc">');
	document.write('</td></tr><tr><td>');
	document.write('<input name="id" type="hidden" value="<?=$id ?>">');
	document.write('</td></tr><tr><td>');
	document.write('<center><input type="submit" name="Submit" value="Submit" class="cbwc"></center>');
	document.write('</td></tr></table><br />');
	document.write('<font class="cbwc">Comment box by</font><br>');
	document.write('<a href="http://www.website-codes.com" class="cbwc">Website Codes</a></center></td></tr></table></form>');
	<?php
}
?>
I have a feeling though that this might not always work?? Is there a better way of doing it?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 2 (0 members and 2 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
Can I insert PHP code into HTML ?? cc79 HTML/XHTML/XML 5 04-12-08 11:00 AM
To use include or embed HTML into my contact.php page dmaldon01 PHP 1 02-17-06 03:40 PM
PHP to generate HTML as loaded from client side mgscom PHP 2 01-14-06 12:02 AM
html page or database table to send by email rpain ASP 5 04-05-04 09:04 AM
Manipulating arrays for display in HTML madsurfer007 PHP 3 08-07-03 08:26 PM


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