jp2php Posted June 30, 2009 Share Posted June 30, 2009 I've got an html page with PHP (at home, not here) that I'm trying to replicate. I've developed in C/C++/C# html and Javascript for over 20 years, but this is my first time to look at PHP. The page is called "index.htm" (note: Not "index.php") and starts on the first line with "<?php". As the code goes down, I see something like this: print <<<END <html> <title>blah</title> <meta>blah blah</meta> and it ends with something like "?END" or something like that. (Again, I don't have the file in front of me) The page I started with had a login screen to authenticate against a stored password, then give access to the company's software installer. The page I need with use the same login screen, then give the user access to a link to download a small database file. Somewhere, I must have missed an opening or closing curley brace "{}", but my html editor doesn't understand PHP. My questions are: What is the "print <<<END" line? I tried searching some PHP sites for it, but it pulled up nothing. Where can I find a cheap/free html editor that understands PHP? Basically, my PHP code should do the following: <?PHP showHeader(); if ((isset(_POST("username")) && (isset(_POST("password"))) { include("vars.php"); if (($username=trim(_POST("username"))) && ($password=trim(_POST("password")))) { // show download // I want to put HTML here. How do I do that? <table> <tr> <th>Download</th><th>Size</th> </tr> <tr> <td><a href="database.mdb">File</a></td><td>200 KB</td> </tr> </table> } else { // show invalid // I want to put HTML here. How do I do that? <table> <tr> <td>Username:</td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td><td><input type="text" name="password" /></td> </tr> <tr> <td><b>Error:</b></td><td><font color=red>Invalid username/password</font></td> </tr> </table> } } else { // display login screen <table> <tr> <td>Username:</td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td><td><input type="text" name="password" /></td> </tr> <tr> <td> </td><td> </td> </tr> </table> } showFooter(); function showHeader() { // html to show a business logo } function showFooter() { // html to show business links, etc. } ?> Is this easy enough to do? Could someone kindly show me how to accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/164240-solved-php-twisted-with-html/ Share on other sites More sharing options...
dzelenika Posted June 30, 2009 Share Posted June 30, 2009 only php code should be in <?php tags (not HTML) For coding i'm using Eclipse PDT http://www.eclipse.org/pdt/downloads/ It's free <?php showHeader(); if ((isset(_POST("username")) && (isset(_POST("password"))) { include("vars.php"); if (($username=trim(_POST("username"))) && ($password=trim(_POST("password")))) { // show download // I want to put HTML here. How do I do that? ?> <table> <tr> <th>Download</th><th>Size</th> </tr> <tr> <td><a href="database.mdb">File</a></td><td>200 KB</td> </tr> </table> <?php } else { // show invalid // I want to put HTML here. How do I do that? ?> <table> <tr> <td>Username:</td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td><td><input type="text" name="password" /></td> </tr> <tr> <td><b>Error:</b></td><td><font color=red>Invalid username/password</font></td> </tr> </table> <?php } } else { // display login screen ?> <table> <tr> <td>Username:</td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td><td><input type="text" name="password" /></td> </tr> <tr> <td> </td><td> </td> </tr> </table> <?php } showFooter(); function showHeader() { // html to show a business logo } function showFooter() { // html to show business links, etc. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/164240-solved-php-twisted-with-html/#findComment-866379 Share on other sites More sharing options...
kartul Posted June 30, 2009 Share Posted June 30, 2009 <<END or <<HTML or <<STUFFLIKETHAT (all of them must end with same name and at start of the line) are ways to display html in php. you could also use echo or print functions. I personally use echo... //don't remember to escape quotes... if (($username=trim(_POST("username"))) && ($password=trim(_POST("password")))) { // show download echo "<table> <tr> <th>Download</th><th>Size</th> </tr> <tr> <td><a href=\"database.mdb\">File</a></td><td>200 KB</td> </tr> </table>"; } cheap editor. hmm... if I remember right then notepad++ has nice colorful code and you can add 3rd party libraries to display php functions and stuff. it's also free Quote Link to comment https://forums.phpfreaks.com/topic/164240-solved-php-twisted-with-html/#findComment-866380 Share on other sites More sharing options...
JJ2K Posted June 30, 2009 Share Posted June 30, 2009 If you want to put HTML in you can either echo it out like: echo ("<b>Some HTML</b>"); or close the PHP block and then just have the HTML as normal. So just for example: if (($username=trim(_POST("username"))) && ($password=trim(_POST("password")))) { // show download // Close off the PHP Block ?> <!-- now we can write HTML as normal --> <table> <tr> <th>Download</th><th>Size</th> </tr> <tr> <td><a href="database.mdb">File</a></td><td>200 KB</td> </tr> </table> <?php //Re-open and re-close the PHP block } else { // show invalid ?> <table> <tr> <td>Username:</td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td><td><input type="text" name="password" /></td> etc... So if you are only using a small bit of HTML it's probably better to echo it out but if its going to be a lot of html it's better to close the php block and re-open it where you need it. Quote Link to comment https://forums.phpfreaks.com/topic/164240-solved-php-twisted-with-html/#findComment-866381 Share on other sites More sharing options...
Maq Posted June 30, 2009 Share Posted June 30, 2009 What is the "print HEREDOC Where can I find a cheap/free html editor that understands PHP? Almost anywhere, but take a look at this thread: http://www.phpfreaks.com/forums/index.php/topic,54859.0.html Quote Link to comment https://forums.phpfreaks.com/topic/164240-solved-php-twisted-with-html/#findComment-866382 Share on other sites More sharing options...
jp2php Posted June 30, 2009 Author Share Posted June 30, 2009 Wow! I got all sorts of answers! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/164240-solved-php-twisted-with-html/#findComment-866388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.