Ilovetopk Posted March 20, 2010 Share Posted March 20, 2010 i get this when trying to execute my change password script. It says it is on line 24. but it looks fine to me... can you guys see the problem? here is the line: $query = "SELECT * FROM members WHERE login='$login' AND passwd='".md5($passwdo)."'"; here is my entire script: <?php //enters connection details require_once('config.php'); //connects to mysql database $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //selects database $db = mysql_select_db(DB_DATABASE, $link); if(!$db) { die("Unable to select database"); } //assigns entered text as variables $passwdo = $_POST['passwdo']; $passwdc = $_POST['passwdc']; $passwdc2 = $_POST['passwdc2']; $login = $_SESSION['SESS_MEMBER_ID'] //checks password with server $query = "SELECT * FROM members WHERE login='$login' AND passwd='".md5($passwdo)."'"; $result = mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } if($result) { if(mysql_num_rows($result) != 1) { echo 'password does not mach password in database.' header("location: change-password-form.php") } //checks for errors if($passwdc != $passwdc2) { $errmsg_arr[] = 'Passwords do not match. please reenter'; $errflag = true; } //error stuff if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: change-password-form.php"); exit(); } //update password on database $query="UPDATE members SET passwd=md5('$passwordc') WHERE login='$login'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //redirects or tells of failure if($result) { header("location: change-password-success.php"); exit(); } else { die("Could not change password, try again in a few minutes, or contact the admin."); } //unset database unset($db); ?> Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/ Share on other sites More sharing options...
Jax2 Posted March 20, 2010 Share Posted March 20, 2010 You forgot a ; after this line: $login = $_SESSION['SESS_MEMBER_ID'] Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028878 Share on other sites More sharing options...
Jax2 Posted March 20, 2010 Share Posted March 20, 2010 You also left out a ; after this line: echo 'password does not mach password in database.' It seems you are missing them on a bunch of lines. Here's another: header("location: change-password-form.php") Here is a fully working version ... always be sure to check your closing brackets <?php //enters connection details require_once('config.php'); //connects to mysql database $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //selects database $db = mysql_select_db(DB_DATABASE, $link); if(!$db) { die("Unable to select database"); } //cleans and assigns entered text as variables $passwdo = $_POST['passwdo']; $passwdc = $_POST['passwdc']; $passwdc2 = $_POST['passwdc2']; $login = $_SESSION['SESS_MEMBER_ID']; //gets password from server $query = "SELECT * FROM members WHERE login=$login AND passwd=md5($passwdo)"; $result = mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //checks for errors if($result) { if(mysql_num_rows($result) != 1) { echo 'password does not mach password in database.'; header("location: change-password-form.php"); } if($passwdc != $passwdc2) { $errmsg_arr[] = 'Passwords do not match. please reenter'; $errflag = true; } //error stuff if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: change-password-form.php"); exit(); } } //update password on database $query="UPDATE members SET passwd=md5('$passwordc') WHERE login='$login'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //redirects or tells of failure if($result) { header("location: change-password-success.php"); exit(); } else { die("Could not change password, try again in a few minutes, or contact the admin."); } //unset database unset($db); ?> Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028881 Share on other sites More sharing options...
Ilovetopk Posted March 20, 2010 Author Share Posted March 20, 2010 okay, now it says theirs a problem on line 71 (the ?> php end tag), see any problems their? the error changed too, it now: Parse error: syntax error, unexpected $end Thanks you two for helping, I've been working with php for a week (you read right, a week) so i'm still getting used to the semi-colon after every line! Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028884 Share on other sites More sharing options...
Jax2 Posted March 20, 2010 Share Posted March 20, 2010 Unexpected end means you're missing a closing bracket } somewhere. I'm sure there's an easier way to find it, but I usually go like this: Start at the beginning of the script, count each { and subtract each } and when you hit the last ?> you should be at 0 (I.e., there's a } for each { ...) if not, you need to figure out which opening bracket is missing the closing bracket. Let me take another look. I couldn't run it fully because it conked out when it was trying to find the includes, which I don't have on my server, of course Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028886 Share on other sites More sharing options...
Jax2 Posted March 20, 2010 Share Posted March 20, 2010 I checked it over again and it all looks right to me... Don't see any missing }'s :/ Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028889 Share on other sites More sharing options...
oni-kun Posted March 20, 2010 Share Posted March 20, 2010 I checked it over again and it all looks right to me... Don't see any missing }'s :/ Please learn a programming style and maybe you will see the obvious flaw there. Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028894 Share on other sites More sharing options...
Jax2 Posted March 20, 2010 Share Posted March 20, 2010 What exactly is it I missed then? I usually indent everything that needs to be. In this case, when I copied the original code, it pasted all over the place so I just quickly got rid of all the white space ... sorry, didn't mean to post an ugly code. I've indented properly and I'm still missing it though, so I guess I'm still not doing it right. Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028898 Share on other sites More sharing options...
oni-kun Posted March 20, 2010 Share Posted March 20, 2010 What exactly is it I missed then? I usually indent everything that needs to be. In this case, when I copied the original code, it pasted all over the place so I just quickly got rid of all the white space ... sorry, didn't mean to post an ugly code. I've indented properly and I'm still missing it though, so I guess I'm still not doing it right. I plugged it into my IDE and it doesn't even say there are 70 lines, Maybe he modified it? Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028910 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 Here you go, Copy and paste this over the old code, You have missed a } at one of the if's make sure if you use two if's you end it with } <?php //enters connection details require_once('config.php'); //connects to mysql database $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //selects database $db = mysql_select_db(DB_DATABASE, $link); if(!$db) { die("Unable to select database"); } //assigns entered text as variables $passwdo = $_POST['passwdo']; $passwdc = $_POST['passwdc']; $passwdc2 = $_POST['passwdc2']; $login = $_SESSION['SESS_MEMBER_ID']; //checks password with server $query = "SELECT * FROM members WHERE login='$login' AND passwd='".md5($passwdo)."'"; $result = mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } if($result) { if(mysql_num_rows($result) != 1) { echo 'password does not mach password in database.'; header("location: change-password-form.php"); } } //checks for errors if($passwdc != $passwdc2) { $errmsg_arr[] = 'Passwords do not match. please reenter'; $errflag = true; } //error stuff if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: change-password-form.php"); exit(); } //update password on database $query="UPDATE members SET passwd=md5('$passwordc') WHERE login='$login'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //redirects or tells of failure if($result) { header("location: change-password-success.php"); exit(); }else{ die("Could not change password, try again in a few minutes, or contact the admin."); } //unset database unset($db); ?> Make sure you keep your code clean too Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1028924 Share on other sites More sharing options...
Ilovetopk Posted March 20, 2010 Author Share Posted March 20, 2010 Here you go, Copy and paste this over the old code, You have missed a } at one of the if's make sure if you use two if's you end it with } <?php //enters connection details require_once('config.php'); //connects to mysql database $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //selects database $db = mysql_select_db(DB_DATABASE, $link); if(!$db) { die("Unable to select database"); } //assigns entered text as variables $passwdo = $_POST['passwdo']; $passwdc = $_POST['passwdc']; $passwdc2 = $_POST['passwdc2']; $login = $_SESSION['SESS_MEMBER_ID']; //checks password with server $query = "SELECT * FROM members WHERE login='$login' AND passwd='".md5($passwdo)."'"; $result = mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } if($result) { if(mysql_num_rows($result) != 1) { echo 'password does not mach password in database.'; header("location: change-password-form.php"); } } //checks for errors if($passwdc != $passwdc2) { $errmsg_arr[] = 'Passwords do not match. please reenter'; $errflag = true; } //error stuff if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: change-password-form.php"); exit(); } //update password on database $query="UPDATE members SET passwd=md5('$passwordc') WHERE login='$login'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //redirects or tells of failure if($result) { header("location: change-password-success.php"); exit(); }else{ die("Could not change password, try again in a few minutes, or contact the admin."); } //unset database unset($db); ?> Make sure you keep your code clean too thanks, i figured that out last night before you posted, and forget to tell you. Quote Link to comment https://forums.phpfreaks.com/topic/195881-parse-errorsyntax-error-unexpected-t_variable/#findComment-1029284 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.