Connecting Tech Pros Worldwide Forums | Help | Site Map

A bad tutorial ?

Newsscanner
Guest
 
Posts: n/a
#1: Jul 27 '05
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>Connect Server</title></head>
<body>
<?
$link =
mysql_connect("localhost",$_POST['username'],$_POST['password'])or
die("Connect Error: ".mysql_error());
print "Successfully connected.\n";
mysql_close($link);
?>
</body>
</html>
Iobviously typed in my own username and password instead of 'username'
and 'password' in the line
"mysql_connect("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\logon.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
Guest
 
Posts: n/a
#2: Jul 27 '05

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>Connect Server</title></head>
> <body>
> <?
> $link =
> mysql_connect("localhost",$_POST['username'],$_POST['password'])or
> die("Connect Error: ".mysql_error());
> print "Successfully connected.\n";
> mysql_close($link);
> ?>
> </body>
> </html>
> Iobviously typed in my own username and password instead of 'username'
> and 'password' in the line
> "mysql_connect("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\logon.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 <?
Newsscanner
Guest
 
Posts: n/a
#3: Jul 27 '05

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>Connect Server</title></head>
>> <body>
>> <?
>> $link =
>>mysql_connect("localhost",$_POST['username'],$_POST['password'])or
>>die("Connect Error: ".mysql_error());
>> print "Successfully connected.\n";
>> mysql_close($link);
>> ?>
>> </body>
>> </html>
>>Iobviously typed in my own username and password instead of 'username'
>>and 'password' in the line
>>"mysql_connect("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\logon.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>Connect Server</title></head>
<body>
<? php
$link = mysql_connect("localhost",$_POST["*****"],$_POST["*****"])or
die("Connect Error: ".mysql_error());
print "Successfully connected.\n";
mysql_close($link);
?>
</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\logon.php on line 5"

Heeeeeeeeeeeelp!!!!
TIA,
Newsscanner.
hoonew
Guest
 
Posts: n/a
#4: Jul 28 '05

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>Connect Server</title></head>
>>> <body>
>>> <?
>>> $link =
>>> mysql_connect("localhost",$_POST['username'],$_POST['password'])or
>>> die("Connect Error: ".mysql_error());
>>> print "Successfully connected.\n";
>>> mysql_close($link);
>>> ?>
>>> </body>
>>> </html>
>>> Iobviously typed in my own username and password instead of
>>> 'username' and 'password' in the line
>>> "mysql_connect("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\logon.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>Connect Server</title></head>
> <body>
> <? php
> $link = mysql_connect("localhost",$_POST["*****"],$_POST["*****"])or
> die("Connect Error: ".mysql_error());
> print "Successfully connected.\n";
> mysql_close($link);
> ?>
> </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\logon.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.
Jeff North
Guest
 
Posts: n/a
#5: Jul 28 '05

re: A bad tutorial ?


On Wed, 27 Jul 2005 19:02:18 +0100, in mailing.database.mysql
Newsscanner <frankied@NOSPAM.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>Connect Server</title></head>
>| <body>
>| <?
>| $link =
>| mysql_connect("localhost",$_POST['username'],$_POST['password'])or
>| die("Connect Error: ".mysql_error());
>| print "Successfully connected.\n";
>| mysql_close($link);
>| ?>
>| </body>
>| </html>
>| Iobviously typed in my own username and password instead of 'username'
>| and 'password' in the line
>| "mysql_connect("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\logon.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.php" 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",'myUsername','myPassword ')
---------------------------------------------------------------
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Newsscanner
Guest
 
Posts: n/a
#6: Jul 28 '05

re: A bad tutorial ?


Jeff North wrote:[color=blue]
> On Wed, 27 Jul 2005 19:02:18 +0100, in mailing.database.mysql
> Newsscanner <frankied@NOSPAM.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>Connect Server</title></head>
>>| <body>
>>| <?
>>| $link =
>>| mysql_connect("localhost",$_POST['username'],$_POST['password'])or
>>| die("Connect Error: ".mysql_error());
>>| print "Successfully connected.\n";
>>| mysql_close($link);
>>| ?>
>>| </body>
>>| </html>
>>| Iobviously typed in my own username and password instead of 'username'
>>| and 'password' in the line
>>| "mysql_connect("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\logon.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.php" 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",'myUsername','myPassword ')
> ---------------------------------------------------------------
> jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
> ---------------------------------------------------------------[/color]
I do, but when I slot it in, as in this:
"<html>
<head><title>Connect Server</title></head>
<body>
<?
$link = mysql_connect("localhost",$_POST['*****'],$_POST['********'])or
die("Connect Error: ".mysql_error());
print "Successfully connected.\n";
mysql_close($link);
?>
<form method="POST" action="kiekteki.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\kiekteki.php on line 5

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

Warning: mysql_connect() [function.mysql-connect]: Access denied for
user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\Abyss
Web Server\htdocs\kiekteki.php on line 5
Connect Error: Access denied for user 'ODBC'@'localhost' (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.
Rincewind
Guest
 
Posts: n/a
#7: Jul 28 '05

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>Connect Server</title></head>
>>> <body>
>>> <?
>>> $link =
>>>mysql_connect("localhost",$_POST['username'],$_POST['password'])or
>>>die("Connect Error: ".mysql_error());
>>> print "Successfully connected.\n";
>>> mysql_close($link);
>>> ?>
>>> </body>
>>> </html>
>>>Iobviously typed in my own username and password instead of 'username'
>>>and 'password' in the line
>>>"mysql_connect("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\logon.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>Connect Server</title></head>
> <body>
> <? php
> $link = mysql_connect("localhost",$_POST["*****"],$_POST["*****"])or
> die("Connect Error: ".mysql_error());
> print "Successfully connected.\n";
> mysql_close($link);
> ?>
> </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\logon.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
Rincewind
Guest
 
Posts: n/a
#8: Jul 28 '05

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.database.mysql
>> Newsscanner <frankied@NOSPAM.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>Connect Server</title>
</head>
<body>
<form method="POST" action="kiekteki.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",$_POST['username'],$_POST['password'])or
die("Connect Error: ".mysql_error());
print "Successfully connected.\n";
mysql_close($link);
?>

</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.
Closed Thread


Similar MySQL Database bytes