+ Reply to Thread
Results 1 to 8 of 8

Thread: Error

  1. #1
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40

    Error

    I'm learnin PHP, so be nice

    This is givin me an error I can't get around... could you take a look?
    PHP Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php

    if(isset($name) && isset($address) && isset($comments)){
    $name=$_POST['name'];
    $address=$_POST['address'];
    $comments=$_POST['comments'];
    print 
    "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
            <td>
            Name:  
    $_GET['name']<br>
            Email:  
    $_GET['address']<br>
            Comments:  
    $_GET['comments']<br>
            </td>
        </tr>
    </table>" 
    or die(php_error());
    }else{
        print 
    "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
            <td>
            Please fill out the form.\n
            </td>
        </tr>
    </table>"
    ;
    }
    }
    ?>
    <form action="<? $_SERVER['PHP_SELF'?> " method="post">
      <p>
        Name:&nbsp;&nbsp;<input type="text" name="name">
      </p>
      <p> 
        E-Mail:&nbsp;&nbsp;<input type="text" name="address">
      </p>
      <p>
        Comments:&nbsp;&nbsp;<textarea cols="20" rows="10" name="comments"></textarea>
      </p>
      <p>
      <input type="submit" value="Submit">
      </p>
    </form>
    </body>
    </html>
    Error:

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program files\easyphp1-7\www\tester.php on line 17


    Thanks.

  2. #2
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    Here is the correct version:

    PHP Code:
     <html> 
    <head> 
    <title>Untitled Document</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    </head> 

    <body> 
    <?php 

    if(isset($name) && isset($address) && isset($comments)){ 
    $name=$_POST['name']; 
    $address=$_POST['address']; 
    $comments=$_POST['comments']; 
    print 
    "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\"> 
        <tr> 
            <td> 
            Name:  "
    .$name."<br> 
            Email:  "
    .$address."<br> 
            Comments:  "
    .$comments."<br> 
            </td> 
        </tr> 
    </table>" 
    or die(php_error()); 
    }else{ 

        print 
    "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\"> 
        <tr> 
            <td> 
            Please fill out the form.\n 
            </td> 
        </tr> 
    </table>"



    ?> 

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
      <p> 
        Name:&nbsp;&nbsp;<input type="text" name="name"> 
      </p> 
      <p> 
        E-Mail:&nbsp;&nbsp;<input type="text" name="address"> 
      </p> 
      <p> 
        Comments:&nbsp;&nbsp;<textarea cols="20" rows="10" name="comments"></text> 
      </p> 
      <p> 
      <input type="submit" value="Submit"> 
      </p> 
    </form> 
    </body> 
    </html>
    I didn't remember all the errors, there were lots of, but the main was

    PHP Code:
            Name:  $_GET['name']<br
            
    Email:  $_GET['address']<br
            
    Comments:  $_GET['comments']<br
    And one extra closing brace "}"

    Hope that helps.
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  3. #3
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40
    Thanks for the help, and it makes sense, but the solution was:
    PHP Code:
     <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php

    if(!empty($_POST['name']) && !empty($_POST['address']) && !empty($_POST['comments'])){
    $name=$_POST['name'];
    $address=$_POST['address'];
    $comments=$_POST['comments'];
    print 
    "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
            <td>
            Name:  
    $name<br>
            Email:  
    $address<br>
            Comments:  
    $comments<br>
            </td>
        </tr>
    </table>" 
    or die(php_error());
    }else{

        print 
    "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
        <tr>
            <td>
            Please fill out the form.\n
            </td>
        </tr>
    </table>"
    ;

    }
    ?>

    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
      <p>
        Name:&nbsp;&nbsp;<input type="text" name="name">
      </p>
      <p>
        E-Mail:&nbsp;&nbsp;<input type="text" name="address">
      </p>
      <p>
        Comments:&nbsp;&nbsp;<textarea cols="20" rows="10" name="comments"></textarea></text>
      </p>
      <p>
      <input type="submit" value="Submit">
      </p>
    </form>
    </body>
    </html>
    Thanks again


  4. #4
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    Practically the same... Cool that you worked it out.

  5. #5
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    40
    Well, seeing as how no one else is really posting new threads, can you explain \n and \r? I hear they are supposed to be new lines and carriage returns, but I only get spaces in the echo()'d output.

  6. #6
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    Steveo31

    can you explain \n and \r?
    True, they are just new lines and carriage returns. But when you echo() them, take care to echo() "<pre>" (preformatted text) tag before, because otherwise browsers will just ignore them or consider like spaces.

    Then, usually, we only use them in pair: "\r\n", most of *nix'es accept just "\n" as well, but to conform to the RFCs you should use only pairs.

  7. #7
    Full Member kitty is on a distinguished road
    Join Date
    Aug 2005
    Posts
    16
    u can search for php manual u will find it alot any function u want,try php.net

  8. #8
    Full Member Marshall is on a distinguished road
    Join Date
    May 2004
    Posts
    69
    Quote Originally Posted by kitty
    u can search for php manual u will find it alot any function u want,try php.net
    This post is over a year old so its safe to assume that ZYV's fixes worked out for him, no need to post and bring it back to the top.

    edit just saw other posts - kitty are you even checking the date on the posts you and replying to? You are posting in posts a year after the last response....
    Last edited by Marshall; September 1st, 2005 at 11:02 PM.
    Eternity-Web Hosting - PHP5 and Directadmin with Installatron Hosting

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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