First script - basic question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • loic_e_bertrand@yahoo.fr

    #1

    First script - basic question

    Hi,

    I created an HTML page with the following code:
    <html>
    <body>
    <form action="everif. php" method="post">
    Name: <input type="text" name="name" size="12"><br>
    First name: <input type="text" name="fname" size="12">
    <input type="submit" value="OK">
    </form>
    </body>

    </html>

    and everif.php contains:
    <?php
    $fname= $_POST['fname'];
    $name= $_POST['name'];
    echo("<center>H i $fname $name</center>");
    ?>


    When I press OK from the HTML page 1 get:
    Parse error: parse error, unexpected T_VARIABLE in
    /var/www/free.fr/d/c/parispain/everif.php on line 2

    where line 2 is:
    $fname= $_POST['fname'];


    Why?

    Thank you.

  • Angelos

    #2
    Re: First script - basic question

    > <?php[color=blue]
    > $fname= $_POST['fname'];
    > $name= $_POST['name'];
    > echo("<center>H i $fname $name</center>");
    > ?>
    >
    >
    > When I press OK from the HTML page 1 get:
    > Parse error: parse error, unexpected T_VARIABLE in
    > /var/www/free.fr/d/c/parispain/everif.php on line 2
    >
    > where line 2 is:
    > $fname= $_POST['fname'];[/color]

    I am not sure but first of all you should check if $_POST['fname']; is set .
    so it should be somthing like :
    if (isset($_POST['fname'])) $fname = $_POST['fname'];
    else $fname = "";

    the same for the $_POST['name']

    Try that ... but then again I am not sure if it solves your problem!!!


    Comment

    • Angelos

      #3
      Re: First script - basic question

      > echo("<center>H i $fname $name</center>");

      And This is not going to echo your $fname and $name ...

      Do that:
      echo ("Hello".$fname ." ".$name);


      Comment

      • Philip Ronan

        #4
        Re: First script - basic question

        loic_e_bertrand @yahoo.fr wrote:
        [color=blue]
        > (snip)
        > everif.php contains:
        > <?php
        > $fname= $_POST['fname'];
        > $name= $_POST['name'];
        > echo("<center>H i $fname $name</center>");
        > ?>
        >
        > When I press OK from the HTML page 1 get:
        > Parse error: parse error, unexpected T_VARIABLE in
        > /var/www/free.fr/d/c/parispain/everif.php on line 2[/color]

        Your code looks Ok to me. You don't need any brackets in the echo statement,
        but it doesn't really matter.

        Perhaps there's a problem with the line breaks in your PHP source. I think
        PHP likes to see a carriage return and linefeed at the end of every line.
        Some editors (especially on Mac systems) use carriage returns but no
        linefeeds.

        --
        phil [dot] ronan @ virgin [dot] net



        Comment

        • Oli Filth

          #5
          Re: First script - basic question

          Angelos wrote:[color=blue][color=green]
          > > echo("<center>H i $fname $name</center>");[/color]
          >
          > And This is not going to echo your $fname and $name ...[/color]

          Yes it is!

          --
          Oli

          Comment

          • Oli Filth

            #6
            Re: First script - basic question

            Philip Ronan wrote:[color=blue]
            > Perhaps there's a problem with the line breaks in your PHP source. I[/color]
            think[color=blue]
            > PHP likes to see a carriage return and linefeed at the end of every[/color]
            line.[color=blue]
            > Some editors (especially on Mac systems) use carriage returns but no
            > linefeeds.[/color]

            Who told you that? You can write a whole PHP script all on line without
            any newlines or carriage returns if you want.

            --
            Oli

            Comment

            • Ewoud Dronkert

              #7
              Re: First script - basic question

              On Tue, 17 May 2005 09:56:07 +0000 (UTC), Angelos wrote:[color=blue][color=green]
              >> echo("<center>H i $fname $name</center>");[/color]
              >
              > And This is not going to echo your $fname and $name ...[/color]

              Yes it is.
              [color=blue]
              > Do that: echo ("Hello".$fname ." ".$name);[/color]

              No, no need for that when using double quotes.


              --
              Firefox Web Browser - Rediscover the web - http://getffox.com/
              Thunderbird E-mail and Newsgroups - http://gettbird.com/

              Comment

              • Ewoud Dronkert

                #8
                Re: First script - basic question

                On Tue, 17 May 2005 11:12:10 +0100, Philip Ronan wrote:[color=blue][color=green]
                >> <?php
                >> $fname= $_POST['fname'];
                >> $name= $_POST['name'];
                >> echo("<center>H i $fname $name</center>");
                >> ?>
                >>
                >> When I press OK from the HTML page 1 get:
                >> Parse error: parse error, unexpected T_VARIABLE in
                >> /var/www/free.fr/d/c/parispain/everif.php on line 2[/color]
                >
                > Your code looks Ok to me.[/color]

                Me too. Did you copy and paste the code in your news post, or type it?
                Your error could be from one space too many, for example after <? or $.


                --
                Firefox Web Browser - Rediscover the web - http://getffox.com/
                Thunderbird E-mail and Newsgroups - http://gettbird.com/

                Comment

                • Philip Ronan

                  #9
                  Re: First script - basic question

                  Oli Filth wrote:
                  [color=blue]
                  > Philip Ronan wrote:[color=green]
                  >> Perhaps there's a problem with the line breaks in your PHP source. I[/color]
                  > think[color=green]
                  >> PHP likes to see a carriage return and linefeed at the end of every[/color]
                  > line.[color=green]
                  >> Some editors (especially on Mac systems) use carriage returns but no
                  >> linefeeds.[/color]
                  >
                  > Who told you that? You can write a whole PHP script all on line without
                  > any newlines or carriage returns if you want.[/color]

                  I just seem to recall having a few parse errors of my own before I set my
                  text editor up to use DOS line breaks.

                  I can't see what else could be wrong with the OP's script.

                  Can you?

                  --
                  phil [dot] ronan @ virgin [dot] net



                  Comment

                  • loic_e_bertrand@yahoo.fr

                    #10
                    Re: First script - basic question

                    I cut and paste the script so I do not think additional spaces could be
                    the origin of the problem.
                    However, I *AM* using a Mac and it could be a carriage return issue...

                    Comment

                    • Ewoud Dronkert

                      #11
                      Re: First script - basic question

                      On 17 May 2005 06:04:03 -0700, loic_e_bertrand @yahoo.fr wrote:[color=blue]
                      > However, I *AM* using a Mac and it could be a carriage return issue...[/color]

                      Yes, probably, if your server is not a Mac.


                      --
                      Firefox Web Browser - Rediscover the web - http://getffox.com/
                      Thunderbird E-mail and Newsgroups - http://gettbird.com/

                      Comment

                      • Philip Ronan

                        #12
                        Re: First script - basic question

                        loic_e_bertrand @yahoo.fr wrote:
                        [color=blue]
                        > I cut and paste the script so I do not think additional spaces could be
                        > the origin of the problem.
                        > However, I *AM* using a Mac and it could be a carriage return issue...
                        >[/color]

                        There are lots of decent free/shareware editors that might help. Try BBEdit
                        and JEdit, for example.

                        --
                        phil [dot] ronan @ virgin [dot] net



                        Comment

                        • loic_e_bertrand@yahoo.fr

                          #13
                          Re: First script - basic question

                          OK,

                          The issue was just an uncorrect unicode space character replacing a
                          normal space, around an '=' sign.

                          Thank you very much,

                          Loïc

                          Comment

                          Working...