unexpected T_VARIABLE problem with simple log in.
Posted: Fri Oct 10, 2008 5:26 am
Hi
I'm copied a simple log in program from the 'PHP 5 in easy steps' book. But I'm getting:
'..Parse error: syntax error, unexpected T_VARIABLE in I:\Program Files\xampp\htdocs\practise\authenticate.php on line 18..'
when testing the code in xampp.
Can anyone help me please and see where the problem is, thanks in advance.
The code with the problem is:
authenticate.php
1 <?php
2
3 $username = $_POST['username'];
4 $password = $_POST['password'];
5 $self = $_SERVER['PHP_SELF'];
6 $referer = $_SERVER['HTTP_REFERER'];
7
8 #if either of the form field is enpty return to the log-in page
9 if( ( !$username ) or ( !$password ) )
10 { header( "Location:$referer" ); exit(); }
11
12 $conn=@mysql_connect( "localhost", "root", "" ) or die( "could not connect." );
13
14 $rs = @mysql_select_db ( "dbforum", $conn )
15 or die("No database selected.")
16
17 #create the mysql query
18 $sql = "select * from members where username=\"$username\" and password = password(\"$password\")";
19
20 #execute the query
21 $rs = mysql_query( $sql, $conn )
22 or die( "Could not execute query" );
23
24 #get number of rows to match username and password
25 $num mysql_numrows( $rs );
26
27 #if there is a match the log-in is athenticated
28 if( $num != 0 )
29 { $msg = "Welcome $username - your log in succeeded!"; }
30
31 else #or return to login page
32 { header( "Location:$referer" ); exit(); }
33 ?>
34 <html><head><title>Log in authenticated</title></head>
35 <body><?php echo( $msg ); ?> </body></html>
Incidentally I've tested it in Editplus and 'mysql_numrows' on line 25 comes up brown, but something tells me it should be red.
The html code being referenced is:
<html><head><title>Log-In page</title></head>
<body>
Please enter your user details to log in here..
<form action = "authenticate.php" method = "post">
Username:<br>
<input type = "text" name = "username">
<br><br>
Password:<br>
<input type = "text" name "password">
<br><br>
<input type = "submit" value = "log In">
</form>
</body>
</html>
Thanks
I'm copied a simple log in program from the 'PHP 5 in easy steps' book. But I'm getting:
'..Parse error: syntax error, unexpected T_VARIABLE in I:\Program Files\xampp\htdocs\practise\authenticate.php on line 18..'
when testing the code in xampp.
Can anyone help me please and see where the problem is, thanks in advance.
The code with the problem is:
authenticate.php
1 <?php
2
3 $username = $_POST['username'];
4 $password = $_POST['password'];
5 $self = $_SERVER['PHP_SELF'];
6 $referer = $_SERVER['HTTP_REFERER'];
7
8 #if either of the form field is enpty return to the log-in page
9 if( ( !$username ) or ( !$password ) )
10 { header( "Location:$referer" ); exit(); }
11
12 $conn=@mysql_connect( "localhost", "root", "" ) or die( "could not connect." );
13
14 $rs = @mysql_select_db ( "dbforum", $conn )
15 or die("No database selected.")
16
17 #create the mysql query
18 $sql = "select * from members where username=\"$username\" and password = password(\"$password\")";
19
20 #execute the query
21 $rs = mysql_query( $sql, $conn )
22 or die( "Could not execute query" );
23
24 #get number of rows to match username and password
25 $num mysql_numrows( $rs );
26
27 #if there is a match the log-in is athenticated
28 if( $num != 0 )
29 { $msg = "Welcome $username - your log in succeeded!"; }
30
31 else #or return to login page
32 { header( "Location:$referer" ); exit(); }
33 ?>
34 <html><head><title>Log in authenticated</title></head>
35 <body><?php echo( $msg ); ?> </body></html>
Incidentally I've tested it in Editplus and 'mysql_numrows' on line 25 comes up brown, but something tells me it should be red.
The html code being referenced is:
<html><head><title>Log-In page</title></head>
<body>
Please enter your user details to log in here..
<form action = "authenticate.php" method = "post">
Username:<br>
<input type = "text" name = "username">
<br><br>
Password:<br>
<input type = "text" name "password">
<br><br>
<input type = "submit" value = "log In">
</form>
</body>
</html>
Thanks