SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot p2ranger's Avatar
    Join Date
    Jan 2001
    Location
    Colorado, USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe I'm going crazy, but this one doesn't make sense. I have the code below. Anyway, when I try viewing the page with or without an $id variable assigned a value, I get nothing in the browser window. However, when I tell it to view the source of the page, there is HTML there. So it should work, but doesn't.

    Jason
    ><>

    http://anvilhead.dns2go.com/jason/ph...g/ringcode.php

    Code:
     
    
    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
           <title>Your Philring Code/title>
    </head>
    <body>
    
    <?php
    
    if(empty($id)):
    
    echo(
    "<form name=\"form1\" method=\"post\" action=\"".$PHP_SELF."\">
      Enter your ID #
      <input type=\"text\" name=\"id\">
      <input type=\"submit\" name=\"Submit\" value=\"Submit\">
    </form>");
    
    
    else:
    
    echo("
    <code>
    
    <!-- START PHILMONT WEB RING HTML  -->
    
    .
    .
    .
    a bunch of example HTML
    .
    .
    .
    
    <!-- END PHILMONT WEB RING HTML -->
    
    
    </code>
    <HR>
    ");
    
    endif;
    
    ?>
    
    </body>
    </html>

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's go over a couple of things here. First off, this is a .php page correct? Let's take out the first line declaring this to be a doc type of html 4.0.

    I have placed comments throughout the rest of the code. Good luck!

    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">// take this line out
    <html>
    <head>
    <title>Your Philring Code/title>
    </head>
    <body>

    <?php
    /*
    your next problem is the following code is not syntactically correct. if statements are followed by a condition that is pass/fail. the condition is in parens, the code to execute needs to be inside curly braces - {}, not colons - :. So the code that you have next, needs to look more like the following:

    if (!isset($id)) {

    echo "some html here";

    } else {

    echo "different html here";

    }


    in php you do not use "endif", end lines or scripts with colons, use semicolons. The above example is how to write a valid php if/else statement
    */
    if(empty($id)):

    echo(
    "<form name=\"form1\" method=\"post\" action=\"".$PHP_SELF."\">
    Enter your ID #
    <input type=\"text\" name=\"id\">
    <input type=\"submit\" name=\"Submit\" value=\"Submit\">
    </form>");


    else:

    /* do not use the parens after an echo. the syntax is:
    echo "some string of text";
    or:
    echo $someVariableName;
    */

    echo("
    <code>

    <!-- START PHILMONT WEB RING HTML -->

    .
    .
    .
    a bunch of example HTML
    .
    .
    .

    <!-- END PHILMONT WEB RING HTML -->


    </code>
    <HR>
    ");

    endif;

    ?>

    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The previous post is incorrect, that use of if/elseif works just fine as does the 4.0 html type decloration. The problem is in this line :

    <title>Your Philring Code/title>

    Have a close look :-) Also, have a look at your HTML source and you'll see everything there, including the above line and form. When that is the case we know it's an HTML issue. Here's an url to keep in mind :

    http://validator.w3.org/

    Silly errors are the worst! :-)

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I stand corrected on all accounts. I learned my php directly from php.net, and have not seen if statements enclosed in colons anywhere. However, I gave it a try and low and behold, it worked.

    If both work, what is considered the standard. Obviously it would be better to adopt the conventions that are most widely used.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree, following this convention is wise (in fact, I ALWAYS use braces) :
    Code:
    if ($var == 'foo') {
      echo 'yes!';
    }
    But it's not required. Check out :
    http://www.php.net/manual/en/control...ive-syntax.php

    Also PEAR is drumming up a coding standard which has interesting information, it can be seen through CVS here :

    http://viewcvs.php.net/viewcvs.cgi/p...viewcvs-markup

  6. #6
    SitePoint Zealot p2ranger's Avatar
    Join Date
    Jan 2001
    Location
    Colorado, USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DOH! I can't believe I missed the closing sign on the tag. Thanks for letting me know.

    I also appreciate the tip on not needing the () on echo. I don't know where I picked that up, but it will save me 2 less key strokes now, thanks.

    I usually use the {} when doing if statements. I was just trying something I saw in my PHP pocket Reference.

    Thanks again
    Jason
    ><>


Bookmarks

Posting Permissions

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