andy_b_1502 Posted September 12, 2011 Share Posted September 12, 2011 Hi guys new to this site and need some help. Im using PHP 5 in easy steps by Mike McGrath, currently creating the register and login scripts for my website. Ive manged to do the register script fine, it drops new user details into the MySQL database fine, however the login script gives the following error when loggin in: Parse error: syntax error, unexpected T_VARIABLE in /hermes/bosweb25a/b109/ipg.removalspacecom/removal space.com/loginscript.php on line 15 I copied the script word-for-word, letter-for-letter, checked and re-checked. I would like to ask you guys if you see something i dont? Here is the script: <?php $username = $_POST['username']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; $referer = $_SERVER['HTTP_REFERER']; #if either form field is empty return to the log-in page if( ( !$username ) or (!$paswword ) ) { header( "Location:$referer" ); exit(); } #connect to MySQL $conn = @mysql_connect ( "removalspacecom.ipagemysql.com", "removal", "123" ) or die("Could not connect" ); #select the specified database $rs = @mysql_select_db( "removal1", $conn ) or die( "Could not select database" ) #create sql query $sql="select * from users where user_name=\"$username\" and password = password( \"$password\" )"; #execute query $rs = myslq_query( $sql, $conn ) or die( "Could not execute query" ); #get number of rows that match username and password $num = mysql_numrows( $rs ); #if there is a match the log-in is authenticated if( $num != 0 ) { $msg = "Welcome $username - your log-in was sucessfull!"; } else #or return to the log-in page { header( "location:$referer" ); exit(); } ?> <html> <head><title>Log-in Authenticated</title></head> <body> <?php echo( $msg ); ?> </body> </html> the error is coming from line 15, the sql query line? why would there be an error from the advisory book? please help me as im stuck on this one. Thanks a lot for any help i get. MOD EDIT: code tags added. Quote Link to comment https://forums.phpfreaks.com/topic/246967-parse-error-t_variable-from-using-a-php-self-help-book-where-am-i-going-wrong/ Share on other sites More sharing options...
Pikachu2000 Posted September 12, 2011 Share Posted September 12, 2011 When posting code, enclose it within the forum's . . . BBCode tags. As for the error, look at what's missing from the end of the previous line . . . Quote Link to comment https://forums.phpfreaks.com/topic/246967-parse-error-t_variable-from-using-a-php-self-help-book-where-am-i-going-wrong/#findComment-1268341 Share on other sites More sharing options...
TOA Posted September 12, 2011 Share Posted September 12, 2011 Also, this typo would cause a problem sometime anyway so you should probably fix it at the same time since it's just a few lines after $rs = myslq_query( $sql, $conn ) or die( "Could not execute query" ); should be $rs = mysql_query( $sql, $conn ) or die( "Could not execute query" ); Quote Link to comment https://forums.phpfreaks.com/topic/246967-parse-error-t_variable-from-using-a-php-self-help-book-where-am-i-going-wrong/#findComment-1268346 Share on other sites More sharing options...
andy_b_1502 Posted September 13, 2011 Author Share Posted September 13, 2011 Thanks a lot guys!! and sorry about not using the tags. So it picked up the error on line 15 but it was really on line 12? something ive got to look out for in future. Thanks again for your help.. Quote Link to comment https://forums.phpfreaks.com/topic/246967-parse-error-t_variable-from-using-a-php-self-help-book-where-am-i-going-wrong/#findComment-1268617 Share on other sites More sharing options...
andy_b_1502 Posted September 13, 2011 Author Share Posted September 13, 2011 Any ideas why the form fails to run the script from the submit button? <html><head><title>Log-in Page</title></head> <body> Please enter your user details to log-in here... <form action = "loginscript.php" method = "post"> <p>Username:<br /> <input type = "text" name = "username" /> <br /> <br /> Password:<br /> <input type = "text" name = "password" /> <br /> <br /> <input type = "submit" value = "Log In" /> </p> <p> </p> <p><a href="index.php">back home... </a></p> </form> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/246967-parse-error-t_variable-from-using-a-php-self-help-book-where-am-i-going-wrong/#findComment-1268625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.