A bad tutorial ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Newsscanner

    #1

    A bad tutorial ?

    Hello,
    I am learning PHP/MySQL at the moment.
    I found what looked like an excellent tutorial site, but the first
    program I wrote already left me with an error to which I cannot find an
    answer.
    I typed in the following program:
    <html>
    <head><title>Co nnect Server</title></head>
    <body>
    <?
    $link =
    mysql_connect(" localhost",$_PO ST['username'],$_POST['password'])or
    die("Connect Error: ".mysql_error() );
    print "Successful ly connected.\n";
    mysql_close($li nk);
    ?>
    </body>
    </html>
    Iobviously typed in my own username and password instead of 'username'
    and 'password' in the line
    "mysql_connect( "localhost",$_P OST['username'],$_POST['password'])or...."

    However, I keep getting the following error when running it from my
    browser:
    "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
    Files\Abyss Web Server\htdocs\l ogon.php on line 5"

    Can anyone enlighten me please ?
    I use PHP v 5.1.1.0 and MySQL v 4.1.13

    Any help will be much appreciated.
    TIA,
    Newsscanner.
  • Rincewind

    #2
    Re: A bad tutorial ?

    On Wed, 27 Jul 2005 19:02:18 +0100, Newsscanner wrote:
    [color=blue]
    > Hello,
    > I am learning PHP/MySQL at the moment.
    > I found what looked like an excellent tutorial site, but the first
    > program I wrote already left me with an error to which I cannot find an
    > answer.
    > I typed in the following program:
    > <html>
    > <head><title>Co nnect Server</title></head>
    > <body>
    > <?
    > $link =
    > mysql_connect(" localhost",$_PO ST['username'],$_POST['password'])or
    > die("Connect Error: ".mysql_error() );
    > print "Successful ly connected.\n";
    > mysql_close($li nk);
    > ?>
    > </body>
    > </html>
    > Iobviously typed in my own username and password instead of 'username'
    > and 'password' in the line
    > "mysql_connect( "localhost",$_P OST['username'],$_POST['password'])or...."
    >
    > However, I keep getting the following error when running it from my
    > browser:
    > "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
    > Files\Abyss Web Server\htdocs\l ogon.php on line 5"
    >
    > Can anyone enlighten me please ?
    > I use PHP v 5.1.1.0 and MySQL v 4.1.13
    >
    > Any help will be much appreciated.
    > TIA,
    > Newsscanner.[/color]


    Have you got the short_open_tag set to true, if not your opening tag needs
    to be <?php not <?

    Comment

    • Newsscanner

      #3
      Re: A bad tutorial ?

      Rincewind wrote:[color=blue]
      > On Wed, 27 Jul 2005 19:02:18 +0100, Newsscanner wrote:
      >
      >[color=green]
      >>Hello,
      >>I am learning PHP/MySQL at the moment.
      >> I found what looked like an excellent tutorial site, but the first
      >>program I wrote already left me with an error to which I cannot find an
      >>answer.
      >>I typed in the following program:
      >> <html>
      >> <head><title>Co nnect Server</title></head>
      >> <body>
      >> <?
      >> $link =
      >>mysql_connect ("localhost",$_ POST['username'],$_POST['password'])or
      >>die("Connec t Error: ".mysql_error() );
      >> print "Successful ly connected.\n";
      >> mysql_close($li nk);
      >> ?>
      >> </body>
      >> </html>
      >>Iobviously typed in my own username and password instead of 'username'
      >>and 'password' in the line
      >>"mysql_connec t("localhost",$ _POST['username'],$_POST['password'])or...."
      >>
      >> However, I keep getting the following error when running it from my
      >>browser:
      >>"Parse error: syntax error, unexpected T_VARIABLE in C:\Program
      >>Files\Abyss Web Server\htdocs\l ogon.php on line 5"
      >>
      >>Can anyone enlighten me please ?
      >>I use PHP v 5.1.1.0 and MySQL v 4.1.13
      >>
      >>Any help will be much appreciated.
      >>TIA,
      >>Newsscanner .[/color]
      >
      >
      >
      > Have you got the short_open_tag set to true, if not your opening tag needs
      > to be <?php not <?[/color]
      I have now adjusted as follows :
      " <html>
      <head><title>Co nnect Server</title></head>
      <body>
      <? php
      $link = mysql_connect(" localhost",$_PO ST["*****"],$_POST["*****"])or
      die("Connect Error: ".mysql_error() );
      print "Successful ly connected.\n";
      mysql_close($li nk);
      ?>
      </body>
      </html>"
      (Replaced the logon details by asterisks for security resons).
      Now I get the following in the browser:
      "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
      Files\Abyss Web Server\htdocs\l ogon.php on line 5"

      Heeeeeeeeeeeelp !!!!
      TIA,
      Newsscanner.

      Comment

      • hoonew

        #4
        Re: A bad tutorial ?

        Newsscanner wrote:[color=blue]
        > Rincewind wrote:
        >[color=green]
        >> On Wed, 27 Jul 2005 19:02:18 +0100, Newsscanner wrote:
        >>
        >>[color=darkred]
        >>> Hello,
        >>> I am learning PHP/MySQL at the moment.
        >>> I found what looked like an excellent tutorial site, but the first
        >>> program I wrote already left me with an error to which I cannot find
        >>> an answer.
        >>> I typed in the following program:
        >>> <html>
        >>> <head><title>Co nnect Server</title></head>
        >>> <body>
        >>> <?
        >>> $link =
        >>> mysql_connect(" localhost",$_PO ST['username'],$_POST['password'])or
        >>> die("Connect Error: ".mysql_error() );
        >>> print "Successful ly connected.\n";
        >>> mysql_close($li nk);
        >>> ?>
        >>> </body>
        >>> </html>
        >>> Iobviously typed in my own username and password instead of
        >>> 'username' and 'password' in the line
        >>> "mysql_connect( "localhost",$_P OST['username'],$_POST['password'])or...."
        >>>
        >>> However, I keep getting the following error when running it from my
        >>> browser:
        >>> "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
        >>> Files\Abyss Web Server\htdocs\l ogon.php on line 5"
        >>>
        >>> Can anyone enlighten me please ?
        >>> I use PHP v 5.1.1.0 and MySQL v 4.1.13
        >>>
        >>> Any help will be much appreciated.
        >>> TIA,
        >>> Newsscanner.[/color]
        >>
        >>
        >>
        >>
        >> Have you got the short_open_tag set to true, if not your opening tag
        >> needs
        >> to be <?php not <?[/color]
        >
        > I have now adjusted as follows :
        > " <html>
        > <head><title>Co nnect Server</title></head>
        > <body>
        > <? php
        > $link = mysql_connect(" localhost",$_PO ST["*****"],$_POST["*****"])or
        > die("Connect Error: ".mysql_error() );
        > print "Successful ly connected.\n";
        > mysql_close($li nk);
        > ?>
        > </body>
        > </html>"
        > (Replaced the logon details by asterisks for security resons).
        > Now I get the following in the browser:
        > "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
        > Files\Abyss Web Server\htdocs\l ogon.php on line 5"
        >
        > Heeeeeeeeeeeelp !!!!
        > TIA,
        > Newsscanner.[/color]

        Replace the whole $_POST["*****"] with your username/password, unless
        you're passing your username and password via a POST form (I'm guessing
        you're not). Either way, it's a good step one in troubleshooting . You
        can put the $_POST array back later once you get it working.

        Comment

        • Jeff North

          #5
          Re: A bad tutorial ?

          On Wed, 27 Jul 2005 19:02:18 +0100, in mailing.databas e.mysql
          Newsscanner <frankied@NOSPA M.netvigator.co .uk> wrote:
          [color=blue]
          >| Hello,
          >| I am learning PHP/MySQL at the moment.
          >| I found what looked like an excellent tutorial site, but the first
          >| program I wrote already left me with an error to which I cannot find an
          >| answer.
          >| I typed in the following program:
          >| <html>
          >| <head><title>Co nnect Server</title></head>
          >| <body>
          >| <?
          >| $link =
          >| mysql_connect(" localhost",$_PO ST['username'],$_POST['password'])or
          >| die("Connect Error: ".mysql_error() );
          >| print "Successful ly connected.\n";
          >| mysql_close($li nk);
          >| ?>
          >| </body>
          >| </html>
          >| Iobviously typed in my own username and password instead of 'username'
          >| and 'password' in the line
          >| "mysql_connect( "localhost",$_P OST['username'],$_POST['password'])or...."
          >|
          >| However, I keep getting the following error when running it from my
          >| browser:
          >| "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
          >| Files\Abyss Web Server\htdocs\l ogon.php on line 5"
          >|
          >| Can anyone enlighten me please ?
          >| I use PHP v 5.1.1.0 and MySQL v 4.1.13
          >|
          >| Any help will be much appreciated.
          >| TIA,
          >| Newsscanner.[/color]

          You should have another form with 2 input boxes (Username and
          Password).
          This other form should have the following html code:
          <form name="???" action="login.p hp" method="post">
          User Name <input type="text" name="username" value="" />
          User Name <input type="password" name="password" value="" />
          <input type="Submit" value="Submit" />
          </form>

          If this is not the case then in your login.php file then change
          $_POST['username'] and $_POST['password'] to the information that you
          want to use i.e.
          mysql_connect(" localhost",'myU sername','myPas sword')
          ---------------------------------------------------------------
          jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
          ---------------------------------------------------------------

          Comment

          • Newsscanner

            #6
            Re: A bad tutorial ?

            Jeff North wrote:[color=blue]
            > On Wed, 27 Jul 2005 19:02:18 +0100, in mailing.databas e.mysql
            > Newsscanner <frankied@NOSPA M.netvigator.co .uk> wrote:
            >
            >[color=green]
            >>| Hello,
            >>| I am learning PHP/MySQL at the moment.
            >>| I found what looked like an excellent tutorial site, but the first
            >>| program I wrote already left me with an error to which I cannot find an
            >>| answer.
            >>| I typed in the following program:
            >>| <html>
            >>| <head><title>Co nnect Server</title></head>
            >>| <body>
            >>| <?
            >>| $link =
            >>| mysql_connect(" localhost",$_PO ST['username'],$_POST['password'])or
            >>| die("Connect Error: ".mysql_error() );
            >>| print "Successful ly connected.\n";
            >>| mysql_close($li nk);
            >>| ?>
            >>| </body>
            >>| </html>
            >>| Iobviously typed in my own username and password instead of 'username'
            >>| and 'password' in the line
            >>| "mysql_connect( "localhost",$_P OST['username'],$_POST['password'])or...."
            >>|
            >>| However, I keep getting the following error when running it from my
            >>| browser:
            >>| "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
            >>| Files\Abyss Web Server\htdocs\l ogon.php on line 5"
            >>|
            >>| Can anyone enlighten me please ?
            >>| I use PHP v 5.1.1.0 and MySQL v 4.1.13
            >>|
            >>| Any help will be much appreciated.
            >>| TIA,
            >>| Newsscanner.[/color]
            >
            >
            > You should have another form with 2 input boxes (Username and
            > Password).
            > This other form should have the following html code:
            > <form name="???" action="login.p hp" method="post">
            > User Name <input type="text" name="username" value="" />
            > User Name <input type="password" name="password" value="" />
            > <input type="Submit" value="Submit" />
            > </form>
            >
            > If this is not the case then in your login.php file then change
            > $_POST['username'] and $_POST['password'] to the information that you
            > want to use i.e.
            > mysql_connect(" localhost",'myU sername','myPas sword')
            > ---------------------------------------------------------------
            > jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
            > ---------------------------------------------------------------[/color]
            I do, but when I slot it in, as in this:
            "<html>
            <head><title>Co nnect Server</title></head>
            <body>
            <?
            $link = mysql_connect(" localhost",$_PO ST['*****'],$_POST['********'])or
            die("Connect Error: ".mysql_error() );
            print "Successful ly connected.\n";
            mysql_close($li nk);
            ?>
            <form method="POST" action="kiektek i.php">
            Enter Username: <input type="text" name="username" size="20">
            Enter Password:<input type="password" name="password" size="20">
            <input type="submit" value="Submit"> <input type="reset">
            </form>
            </body>
            </html>"
            I get the following errors in the browser:
            "Notice: Undefined index: ****** in C:\Program Files\Abyss Web
            Server\htdocs\k iekteki.php on line 5

            Notice: Undefined index: ******** in C:\Program Files\Abyss Web
            Server\htdocs\k iekteki.php on line 5

            Warning: mysql_connect() [function.mysql-connect]: Access denied for
            user 'ODBC'@'localho st' (using password: NO) in C:\Program Files\Abyss
            Web Server\htdocs\k iekteki.php on line 5
            Connect Error: Access denied for user 'ODBC'@'localho st' (using
            password: NO)"

            (Once again, the stars in the text were put there by me for security
            reasons as they revealed my password etc.)

            Thanks,
            Newsscanner.

            Comment

            • Rincewind

              #7
              Re: A bad tutorial ?

              On Wed, 27 Jul 2005 23:10:48 +0100, Newsscanner wrote:
              [color=blue]
              > Rincewind wrote:[color=green]
              >> On Wed, 27 Jul 2005 19:02:18 +0100, Newsscanner wrote:
              >>
              >>[color=darkred]
              >>>Hello,
              >>>I am learning PHP/MySQL at the moment.
              >>> I found what looked like an excellent tutorial site, but the first
              >>>program I wrote already left me with an error to which I cannot find an
              >>>answer.
              >>>I typed in the following program:
              >>> <html>
              >>> <head><title>Co nnect Server</title></head>
              >>> <body>
              >>> <?
              >>> $link =
              >>>mysql_connec t("localhost",$ _POST['username'],$_POST['password'])or
              >>>die("Conne ct Error: ".mysql_error() );
              >>> print "Successful ly connected.\n";
              >>> mysql_close($li nk);
              >>> ?>
              >>> </body>
              >>> </html>
              >>>Iobviously typed in my own username and password instead of 'username'
              >>>and 'password' in the line
              >>>"mysql_conne ct("localhost", $_POST['username'],$_POST['password'])or...."
              >>>
              >>> However, I keep getting the following error when running it from my
              >>>browser:
              >>>"Parse error: syntax error, unexpected T_VARIABLE in C:\Program
              >>>Files\Abys s Web Server\htdocs\l ogon.php on line 5"
              >>>
              >>>Can anyone enlighten me please ?
              >>>I use PHP v 5.1.1.0 and MySQL v 4.1.13
              >>>
              >>>Any help will be much appreciated.
              >>>TIA,
              >>>Newsscanne r.[/color]
              >>
              >>
              >>
              >> Have you got the short_open_tag set to true, if not your opening tag needs
              >> to be <?php not <?[/color]
              > I have now adjusted as follows :
              > " <html>
              > <head><title>Co nnect Server</title></head>
              > <body>
              > <? php
              > $link = mysql_connect(" localhost",$_PO ST["*****"],$_POST["*****"])or
              > die("Connect Error: ".mysql_error() );
              > print "Successful ly connected.\n";
              > mysql_close($li nk);
              > ?>
              > </body>
              > </html>"
              > (Replaced the logon details by asterisks for security resons).
              > Now I get the following in the browser:
              > "Parse error: syntax error, unexpected T_VARIABLE in C:\Program
              > Files\Abyss Web Server\htdocs\l ogon.php on line 5"
              >
              > Heeeeeeeeeeeelp !!!!
              > TIA,
              > Newsscanner.[/color]

              take the space out of the <?php in your script between the ? and php and it
              should work

              Comment

              • Rincewind

                #8
                Re: A bad tutorial ?

                On Thu, 28 Jul 2005 09:57:17 +0100, Newsscanner wrote:
                [color=blue]
                > Jeff North wrote:[color=green]
                >> On Wed, 27 Jul 2005 19:02:18 +0100, in mailing.databas e.mysql
                >> Newsscanner <frankied@NOSPA M.netvigator.co .uk> wrote:
                >>
                >>[color=darkred]
                >>>| Hello,
                >>>| I am learning PHP/MySQL at the moment.
                >>>| I found what looked like an excellent tutorial site, but the first
                >>>| program I wrote already left me with an error to which I cannot find an
                >>>| answer.[/color][/color][/color]
                <snip>[color=blue]
                > Thanks,
                > Newsscanner.[/color]

                I've seen that tutorial and as far as I can see, you seem to be confused
                about the whole process.

                The login form:

                <html>
                <head>
                <title>Connec t Server</title>
                </head>
                <body>
                <form method="POST" action="kiektek i.php">
                Enter Username: <input type="text" name="username" size="20">
                Enter Password:<input type="password" name="password" size="20">
                <input type="submit" value="Submit"> <input type="reset">
                </form>
                </body>
                </html>
                is seperate from the php script that connects to the server, using the
                above will bring up a box for you to enter your username and password (for
                your MySQL installation).

                Once you have entered the details this form passes on the variables
                'username' and 'password' to your script named kiekteki.php. This will then
                process the information and connect to Mysql, this part does that:

                <html>

                <head>
                <title>kiekteki </title>
                </head>

                <body>

                <?php
                $link = mysql_connect(" localhost",$_PO ST['username'],$_POST['password'])or
                die("Connect Error: ".mysql_error() );
                print "Successful ly connected.\n";
                mysql_close($li nk);
                ?>

                </body>

                </html>
                and should be saved as kiekteki.php.

                Do not change $_POST['username'] and $_POST['password'] these are the names
                of the variables you are passing(posting ) from your login script.

                try it and see.

                I would suggest that you try the tutorial at
                http://www.php-mysql-tutorial.com/ I think you will find it much better.

                Comment

                Working...