Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Php Coding Help, just when I thought I had it
imajin8shun
post Jul 6 2005, 08:40 AM
Post #1


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 38
Joined: 30-June 05
Member No.: 6,728



Okay now... I'm pretty sure I have php and all that working but I preview it and it shows NOTHING! Zippo Nadda Zlich! Now I'm going to paste the code so forgive me if I use the wrong box thingy.

CODE
<?phpecho <<<END<head>
<TITLE>FEAR AND LOATHING | did I say that out loud? can they hear me?</TITLE>
<LINK media=screen href="index.css" type=text/css rel=stylesheet>
<META content="Microsoft FrontPage 4.0" name=GENERATOR>

<body bgColor=#C7B299 leftMargin=0 topMargin=0 onload="window.defaultStatus='FEAR AND LOATHING IN LAS VEGAS';" marginheight="0" marginwidth="0">

<center>



<table cellSpacing=0 cellPadding=0 style="border: 0pt;">
<tr vAlign=top>
<td><img src="new.jpg" border=0></td>
</tr></table><table cellSpacing=0 cellPadding=2 width=529 style="border: 0pt;">
<tr vAlign=top>
<td width=150 bgColor=C69C6D>

<?php include("menu.php"); ?>

</td>
<td cellpadding="0" width=371 bgColor=#C69C6D style="border: 0pt;">

<?php include("blog.php"); ?>

</td>
</tr></table>

       
 
</td>
</tr></table>
</table>



</body><END ?phpecho>


Can someone please hcek this to see if its right, and if not can you please correct it for me? Thanks in advanced.
Go to the top of the page
 
+Quote Post
SunBlind
post Jul 6 2005, 11:23 AM
Post #2


Advanced Member
Group Icon

Group: Members
Posts: 128
Joined: 27-June 05
From: Belington, WV
Member No.: 6,653



Oh, sweetheart, we need to talk...


First of all, your page starts off with an echo (which is supposed to look like this:)
CODE
<?php echo(); ?>
I admit that I'm not the brightest crayon in the box, and I've never seen a page begin this way, so I'll automatically assume that it's a mistake... What are you echoing? Second of all, if you're going to code your entire page in PHP, you just can't open with a PHP tag and then start HTML'ing... It's going to cause parse errors. Your page doesn't have to begin with PHP to become a .php page. From what I can see, the whole point of making this a PHP file is to include your blog and menu, right? All you have to do is take out the deformed echo tags at the beginning and end of the codes, keep your include code, and save the page as a PHP file. Here, I'll do the work for you:
CODE
<html><head>
<TITLE>FEAR AND LOATHING | did I say that out loud? can they hear me?</TITLE>
<LINK media=screen href="index.css" type=text/css rel=stylesheet>
<META content="Microsoft FrontPage 4.0" name=GENERATOR>

<body bgColor=#C7B299 leftMargin=0 topMargin=0 onload="window.defaultStatus='FEAR AND LOATHING IN LAS VEGAS';" marginheight="0" marginwidth="0">

<center>



<table cellSpacing=0 cellPadding=0 style="border: 0pt;">
<tr vAlign=top>
<td><img src="new.jpg" border=0></td>
</tr></table><table cellSpacing=0 cellPadding=2 width=529 style="border: 0pt;">
<tr vAlign=top>
<td width=150 bgColor=C69C6D>

<?php include("menu.php"); ?>

</td>
<td cellpadding="0" width=371 bgColor=#C69C6D style="border: 0pt;">

<?php include("blog.php"); ?>

</td>
</tr></table>

     

</td>
</tr></table>
</table>



</body></html>


And one more thing: If your page is coded in PHP, unless you have PHP installed on your computer and your file is saved in the directory that the installation reads (usually htdocs) when you preview it you'll just see code. If you program the page with an HTML/PHP mix, you'll only be able to see the HTML, but at least it's a lot prettier than brackets and question marks :/ Good luck! Hope this helped a little.
Go to the top of the page
 
+Quote Post
imajin8shun
post Jul 6 2005, 11:42 AM
Post #3


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 38
Joined: 30-June 05
Member No.: 6,728



I changed it, uploaded to my public_html folder in astahost... comes up saying theres an error in line 1... the first line is "<html><head>" just like you said sunblind. I'm not saying its your fault or anything... I'm just saying it didnt work, any ideas why?
Go to the top of the page
 
+Quote Post
vizskywalker
post Jul 6 2005, 01:20 PM
Post #4


Techno-Necromancer
Group Icon

Group: Members
Posts: 1,018
Joined: 13-January 05
From: The Net
Member No.: 2,127



Okay, first of all, Sunblind is only half right. Echo is a very special command in php and has three main forms:
1) echo();
2) echo"";
3) echo <<<END
END;

The third is for large blocks of html code so except for needing a space between <?php and echo and between <<<END and <html> nothing is wrong with the first line.

However, you do need an <html> tag before your <head> tag as well as after the last html statement.

Second major issue, once you invoke the php compiler with the <?php tag, you cannot reopen it. The way to add your php statements is not by adding (for example) <?php include("menu.php"); ?> but by closing the echo and simply adding the php code like so:
CODE
END;
include("menu.php");
Then to reopen a large echo, create a large echo block the same way you did the first time but instead of making the ending word END make it something else, like ENDHTML.

Then, after your </body> tag place an </html> tag and on the next line write ENDHTML; and on the last line use the tag to close the php compiler: ?>

Because most of your code is html, you could do what Sunblind said, and instead of echoing the html, simply write the html and where you want the php code, invoke the compiler the same way you tried to do in your code.

Also, be sure you save the page with a .php extension or everything will be treated as html code, not php code.

If any of this confuses you, be sure to ask more questions.

~Viz
Go to the top of the page
 
+Quote Post
overture
post Jul 6 2005, 01:22 PM
Post #5


Premium Member
Group Icon

Group: Members
Posts: 208
Joined: 6-September 04
From: England
Member No.: 315



The code works fine for me. It may be the including files which may be the issue, there maybe something wrong with them. Try making a blank html page and type something in it and save it as test.html. Then include that and nothing else:

CODE

<html><head>
<TITLE>FEAR AND LOATHING | did I say that out loud? can they hear me?</TITLE>
<LINK media=screen href="index.css" type=text/css rel=stylesheet>
<META content="Microsoft FrontPage 4.0" name=GENERATOR>

<body bgColor=#C7B299 leftMargin=0 topMargin=0 onload="window.defaultStatus='FEAR AND LOATHING IN LAS VEGAS';" marginheight="0" marginwidth="0">

<center>



<table cellSpacing=0 cellPadding=0 style="border: 0pt;">
<tr vAlign=top>
<td><img src="new.jpg" border=0></td>
</tr></table><table cellSpacing=0 cellPadding=2 width=529 style="border: 0pt;">
<tr vAlign=top>
<td width=150 bgColor=C69C6D>

</td>
<td cellpadding="0" width=371 bgColor=#C69C6D style="border: 0pt;">

<?php include("test.html"); ?>

</td>
</tr></table>

   

</td>
</tr></table>
</table>



</body></html>


If that works fine and it shows what you have written in the html file then it is most likely something wrong with your menu.php or blog.php.
Go to the top of the page
 
+Quote Post
SunBlind
post Jul 6 2005, 05:08 PM
Post #6


Advanced Member
Group Icon

Group: Members
Posts: 128
Joined: 27-June 05
From: Belington, WV
Member No.: 6,653



Yeah I figured I'd screw that up somehow Lol Sorry, imajin8shun. I'll just go back to playing in the Photoshop forum where I belong...

*slowly backs away*
Go to the top of the page
 
+Quote Post
imajin8shun
post Jul 6 2005, 07:30 PM
Post #7


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 38
Joined: 30-June 05
Member No.: 6,728



Okay thanks. Umm Well I figured out what was wrong, I had the code in their twice huh.gif lol so I think that might of done something, lol. Anyways I fixed it, uploaded it then viewed it, and it all seemed to be working, except for when I view source and for some reason the php coding I used didn't showup, instead it came up with all the old html codes I used in the orginal layout before I created a php one. huh.gif I find this to be very strange.

http://www.fearandloathing.astahost.com/php1.php

Thats the link, if you go to it and view source you'll see what I mean. But I have got school to go to so I won't be able to try out the other options you guys have given me, but as soon as I get back I'll try them out and let you guys know if it worked. Cheers.
Go to the top of the page
 
+Quote Post
vujsa
post Jul 6 2005, 09:50 PM
Post #8


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



OK, that was a good practice run imajin8shun.

We gave you a sample to play with you tried it had a few problems and learned how to use a limited amount of php.

Because php is a server sided script, the php will not show up in the view source. The server reads the php and returns the required HTML to produce the page you designed. The browser will never see the php, only the server. While javascript is a client side script, it will show up in the view source.

The exaple shown here is an HTML document that utilizes PHP for semi-dynamic content.

I suggest that your next practice script be an attempt to create another document that uses even more PHP. Perhapes a routine to insert the current date and time into the page.

Try to put something like Today is July 6th, 2005 into your page. To do this first start at the top of the page with your PHP open tag.
CODE
<?php


Then we need to assign a variable to the date.
CODE
$today = date("F jS,Y");


Then close our PHP.
CODE
?>


Next in our page we call for the date.
CODE
<b>Today is <?php echo $today; ?>.</b>


Here it is all together:
CODE
<?php
$today = date("F jS,Y");
?>
<html>
   <head>
       <title>
           HTML-PHP Current Date Test
       </title>
   </head>

   <body>
       <center>
           My Title!
       </center><br>
   <b>Today is <?php echo $today; ?>.</b><br>
   <br>
       Welcome to my test page!
   </body>
</html>


Hopefully this will show you a few more ways to combine HTML and PHP.

Happy Scripting. cool.gif

vujsa
Go to the top of the page
 
+Quote Post
imajin8shun
post Jul 7 2005, 02:58 AM
Post #9


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 38
Joined: 30-June 05
Member No.: 6,728



Thanks for all your help guys... I think I'm finally starting to understand php. Just a few more tests and I should have my website up and running using php within no time. biggrin.gif
Go to the top of the page
 
+Quote Post
mastercomputers
post Jul 7 2005, 03:53 AM
Post #10


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



PHP start tag = <?php
PHP end tag = ?>
PHP short start tag = <?
PHP short echo tag = <?=

There's no <?phpecho or ?phpecho>

You must have white space between <?php e.g. <?php echo 'some text'; ?>

Examples:

<?php echo 'this is simple php'; ?>
<? echo 'this may or may not work, dependant if short_tags = on in php.ini'; ?>
<?= 'relies on short_tags being on'; ?>

To be more cross supported, use full tags compared to short tags, in fact, don't ever use short tags.

I've cleaned up your code, fixed a few noticable problems, so hopefully this is a starting point for you to write better well-formed web pages, and better PHP programming guides, just look at the difference of your above code to my below code.

CODE
<?php
$menu_php = 'menu.php';
if(file_exists($menu_php))
   $menu = file($menu_php);
else
   $menu = 'Error: menu does not exist';
$blog_php = 'blog.php';
if(file_exists($blog_php))
   $blog = file($blog_php);
else
   $blog = 'Error: blog does not exist';
echo <<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
   <title>FEAR AND LOATHING | did I say that out loud? can they hear me?</title>
   <link media="screen" href="index.css" type="text/css" rel="stylesheet" />
</head>
<body style="background-color: #C7B299; margin: 0px;" onload="window.defaultStatus='FEAR AND LOATHING IN LAS VEGAS';">
   <div align="center">
   <table cellspacing="0" cellpadding="0" style="border: 0pt;">
       <tr>
           <td>
           <img src="new.jpg" style="border: 0pt;" alt="new" />
           </td>
       </tr>
   </table>
   <table cellspacing="0" cellpadding="2" width="529" style="border: 0pt;">
       <tr>
           <td width="150" style="background-color: #C69C6D;">
           $menu
           </td>
           <td width="371" style="background-color: #C69C6D; border: 0pt;">
           $blog
           </td>
       </tr>
   </table>
   </div>
</body>
</html>

END;
?>



Cheers,


MC
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Get The Current Running Machine Ip-c/c++ Coding(2)
  2. Coding Layouts(4)
  3. Game Coding(4)
  4. I Thought It Was _my_ Sql, Now Sun Owns It(7)
  5. Web1000.com: Web Hosting(4)
  6. Can Anyone Help With Html/coding?(2)
  7. Secure Php Coding(10)
  8. Coding Html Properly In The New Age(15)
  9. Where Can I Seek Help On Flash Coding ?(5)
  10. Scrutinize My Chess Game!(6)
  11. Post/credit Count Add-on(4)
  12. Coding Asp In Javascript(2)
  13. C++ Template Coding Conundrum...(5)
  14. PHP Coding Help!(5)
  15. Thought I'd Introduce Myself(7)
  1. Photoshop Text Effect(1)
  2. MySQL & PHP coding(9)
  3. Need Help With Floating Layout!(11)
  4. {} Html'ing & Basic Codes {}(0)
  5. Coding A Private Message System(4)
  6. Budokai Tenkaichi, Just Bought It(2)
  7. Need Help In Coding A Search Engine(1)
  8. Need Help With Floating Layout!(0)
  9. At One Point, I Thought All Free Web Hosts Sucked(4)
  10. Any Thoughts One The New Wild Arms Game(3)
  11. Css Coding(3)
  12. I Know You Exist, But I Dont Think You Are Real.(29)
  13. Hosting Credits And More(4)
  14. Megaman, Megaman X, & Megaman Zero Series(5)
  15. Coding For Halflife 2...(2)


 



- Lo-Fi Version Time is now: 15th October 2008 - 07:14 PM