Jump to content

Parse error:syntax error, unexpected T_VARIABLE


Ilovetopk

Recommended Posts

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); 

?>

Link to comment
Share on other sites

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); 
?>

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

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 :P

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.