Jump to content

Recommended Posts

I am making a change password form but I keep getting errors that I don't know how to fix

 

here is my code:

 

<?php
// Include the PHP script that contains the session information.
include('includes/session.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="includes/base.css" title="Default" media="screen" />
<script type="text/javascript" src="includes/include.js"></script>

</head>

<body>

<?php include('includes/top.php'); ?>

<div id="main">

	<div id="sideBarLeft"><?php include('includes/left.php'); ?></div>

	<div id="content"><div class="innerContent">
		<div class="title">Change Password</div>
		<?php
			//Check if the form has been submitted
			if (isset($_POST['submitted'])) {

			//Connect to Database
			require_once ('../../datemysql_connect.php');

			//Create a function for escpaing the data.
			function escape_data ($data) {
				global $dbc; //Need the connection.
				if (ini_get('magic_quotes_gpc')) {
					$data = stripslashes($data);
				}
				return mysql_real_escape_string (trim($data), $dbc);
			}//end function

			$errors = array(); // initialize error array.

			//check for email
			if (empty($_POST['email'])) {
				$errors[] = 'You forgot to enter your email address.';
			} else {
				$e = escape_date($_POST['email']);
				}	

			//check for an existing password
			if (empty($_POST['password'])) {
				$errors[] = 'You forgot to enter your existing password.';
			} else {
				$p = escape_data($_POST['password']);
			}

			//check for a password and match against the confirmed password.
			if (!empt($_POST['password1'])) {
				if ($_POST['password1'] != $_POST['password2']) {
					$errors[] = 'Your new password did not match the confirmed new password.';
				} else {
					$no problem = escape_data($_POST['password1']);
				}

			if (empty($errors)) {//if everything's OK

			//Check that htye've entered the right email address/password combination.
			$query = "SELECT user_id FROM users WHERE (email='$e' AND password=SHA('$p') )";
			$result = mysql_query($query);
			$num = mysql_num_rows($results);
			if (mysql_num_rows($result) == 1) {//match was made.

				//Get the user_id.
				$row = mysql_fetch_array ($result, MYQSL_NUM);

				//Make the UPDATE query.
				$query = "UPDATE users SET password=SHA('$no problem') WHERE user_id=$row[0]";
				$result = @mysql_query ($query);
				if (mysql_affected_rows() ==1) {//if it ran ok

					//send an email, if desired.


					//Print a message.
					echo 'Thank You! - Your Password has been updated.';

					//quit script
					exit();

				} else { //if it did not run ok.
					echo 'Your Password could not be changed.';
					echo mysql_error() . ' Query: ' . $query . ' '; //debuggin message.
					exit();
				}

			} else { //invalid email address/password combination.
				echo 'The email address and password do not match those on file.';
			}

			} else { // report the errors.

				echo 'Please Try again';

			}//end of if (empty($errors)) IF.

			mysql_close(); //close the database connection.

			}//end of main submit conditional
			?>

			<form action="password.php" method="post">
				<table border="0" cellpadding="0" cellspacing="5">
					<tr>
						<td>Email Address:</td>
						<td>
						  <input type="text" class="required" name="email" id="focus" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" size="20" maxlength="40">
						</td>
					</tr>
					<tr>
						<td>Current Password:</td>
						<td>
						  <input type="password" class="required" name="password" value="" size="10" maxlength="20">
						</td>
					</tr>
					<tr>
						<td>New Password:</td>
						<td>
						  <input type="password" class="required" name="password1" value="" size="10" maxlength="20">
						</td>
					</tr>
					<tr>
						<td>Confirm Password:</td>
						<td>
						  <input type="password" class="required" name="password2" value="" size="10" maxlength="20">
						</td>
					</tr>
					<tr>
						<td><input type="submit" class="button" name="submit" value="Change Password"></td>
					</tr>
					<tr>
						<td><input type="hidden" name="submitted" value="TRUE"></td>
					</tr>														
				</table>
			</form>


	</div>
		<div id="footer"><?php include('includes/bottom.php'); ?></div>
	</div>
</div>

</body>
</html>

 

Right now the error is:

Parse error: syntax error, unexpected $end in /home/nayliner/public_html/datetiki/password.php on line 154

 

and that is my </html>

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/66191-solved-error-help/
Share on other sites

yes, you're one closing brace short, from the first if().  it helps to count the number of braces in your script.  go up one for each opening brace, subtract one for each closing brace you see.  if you've got a positive number by the end of your script, you're missing a closing brace (or more).  you're also going to find you get an undefined function error on this line:

 

if (!empt($_POST['password1'])) {

 

can you see why?

Link to comment
https://forums.phpfreaks.com/topic/66191-solved-error-help/#findComment-331111
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.