Jump to content


Photo

Touble with PHP Script


  • Please log in to reply
6 replies to this topic

#1 rfwrangler

rfwrangler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 20 August 2006 - 01:56 AM

I am working on a script to allow users to update their profiles on a website and I am having problems.  I can not find where the script is hanging up.

Here is the script that I am having trouble with:
<?php
//Assign $_POST[variables] to simple variables that can be used in PHP
$password_new = $_POST['password_new'];
$password_new2 = $_POST['password_new2'];
$password_old = $_POST['password_old'];
$sex = $_POST['sex'];
$address_1 = $_POST['address_1'];
$address_2 = $_POST['address_2'];
$city = $_POST['city'];
$state_prov = $_POST['state_prov'];
$country = $_POST['country'];
$zipcode = $_POST['zipcode'];
$user_info = $_POST['user_info'];
$tm_club = $_POST['tm_club'];
$tm_club_num = $_POST['tm_club_num'];
$club_info = $_POST['club_info'];
$newsletter = $_POST['newsletter'];
$picture_file = $_POST['picture_file'];
//stripslashes from variables.
$password_new = stripslashes($password_new);
$password_new2 = stripslashes($password_new2);
$password_old = stripslashes($password_old);
$sex = stripslashes($sex);
$address_1 = stripslashes($address_1);
$address_2 = stripslashes($address_2);
$city = stripslashes($city);
$state_prov = stripslashes($state_prov);
$country = stripslashes($country);
$zipcode = stripslashes($zipcode);
$user_info = stripslashes($user_info);
$tm_club = stripslashes($tm_club);
$tm_club_num = stripslashes($tm_club_num);
$club_info = stripslashes($club_info);
$newsletter = stripslashes($newsletter);
$picture_file = stripslashes($picture_file);
//process data from variables
//error checking of password change
//Check if all fields are provided.
if (isset($password_new) {
	if((!$password_new2) || (!$password_old)) {
		echo "You forgot to fill in a value in order to change your password!<br />\n";
		if(!$password_old) {
			echo "Please fill in your old password.<br />\n";
		}
		if(!$password_new2) {
			echo "Please fill in the new password again.<br />\n";
		}
		include 'Resources/PHPModules/profile_update.php';
		include 'Resources/HTML/error_include_registration.html';
		exit()
		};
	if($password_new != $password_new2) {
		echo "Both enteries of the new password must match!<br />\n";
			include 'Resources/PHPModules/profile_update.php';
			include 'Resources/HTML/error_include_registration.php';
	exit()
	};
	$sql_check = mysql_query
	("SELECT * FROM members WHERE member_name='$member_name' AND password='$password_old'");
	$sql_check_num = mysql_num_rows($sql_check);
		if($sql_check_num == 0) {
			echo "Your Username and Old Password did not match in our database.&nbsp;&nbsp;Please, try 
			again.<br />\n";
				include 'Resources/PHPModules/profile_update.php';
				include 'Resources/HTML/error_include_registration.html';
		exit();
		}
//If the above checks out then encrypt the password and enter it into the database
		$db_password=md5($password_new);
	$sql_password = mysql_query
		("UPDATE members SET password='$db_password' WHERE member_name='$member_name'");
}
//Set new values to database.
/*echo "<table align=\"center\">\n
		<tr>\n
			<td colspan=\"2\" class\"alert\" alignment=\"justify\">Your profile has been updated in our
			database:(items in red have been changed)</td>\n
		</tr>\n
		<tr>\n
			<td align=\"left\">First Name:</td>\n
			<td align=\"left\">$first_name</td>\n
		<\tr>\n
		<tr>\n
			<td align=\"left\">Last Name:</td>\n
			<td align=\"left\">$last_name</td>\n
		</tr>\n
		<tr>
			<td align=\"left\">Username:</td>\n
			<td align=\"left\">$member_name</td>\n
		</tr>\n";
if(isset($password)) {
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">PASSWORD:</td>\n
			<td class=\"alert\" align=\"left\">Your new password was sent to your Email Address for 
			security reasons</td>
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Password:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
	}		 			
if(isset($sex)) {
	$sql_sex = mysql_query
		("UPDATE members SET sex='$sex' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">SEX:</td>\n
			<td class=\"alert\" align=\"left\">$sex</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Sex:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";			
	}
	echo "<tr>\n
			<td align=\"left\">Email Address:</td>\n
			<td align=\"left\">$email_address</td>\n
		</tr>\n";
if(isset($address_1)) {
	$sql_address_1 = mysql_query
		("UPDATE members SET address_1='$address_1' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">ADDRESS 1:</td>\n
			<td class=\"alert\" align=\"left\">$address_1</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Address 1:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($address_2)) {
	$sql_address_2 = mysql_query
		("UPDATE members SET address_2='$address_2' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">ADDRESS 2:</td>\n
			<td class=\"alert\" align=\"left\">$address_2</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Address 2:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($city)) {
	$sql_city = mysql_query
		("UPDATE members SET city='$city' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">CITY:</td>\n
			<td class=\"alert\" align=\"left\">$city</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">City:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($state_prov)) {
	$sql_state_prov = mysql_query
		("UPDATE members SET state_prov='$state_prov' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">STATE/PROVIDENCE:</td>\n
			<td class=\"alert\" align=\"left\">$state_prov</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">State/Providence:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($country)) {
	$sql_country = mysql_query
		("UPDATE members SET country='$country' WHERE member_name='$member_name'");
		echo "<tr>\n
			<td class=\"alert\" align=\"left\">COUNTRY:</td>\n
			<td class=\"alert\" align=\"left\">$country</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Country:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($zipcode)) {
	$sql_zipcode = mysql_query
		("UPDATE members SET zipcode='$zipcode' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">ZIP CODE:</td>\n
			<td class=\"alert\" align=\"left\">$zipcode</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Zip Code:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($user_info)) {
	$user_info2 = htmlspecialchars($user_info);
	$sql_user_info = mysql_query
		("UPDATE members SET user_info='$user_info2' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">USER INFORMATION:</td>\n
			<td class=\"alert\" align=\"left\">$user_info</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">User Information:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($tm_club)) {
	$sql_tm_club = mysql_query
		("UPDATE members SET tm_club='$tm_club' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">TOASTMASTERS CLUB:</td>\n
			<td class=\"alert\" align=\"left\">$tm_club</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Toastmasters Club:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($tm_club_num)) {
	$sql_tm_club_num = mysql_query
		("UPDATE members SET tm_club_num='$tm_club_num' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">CLUB NUMBER:</td>\n
			<td class=\"alert\" align=\"left\">$tm_club_num</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Club Number:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($club_info)) {
	$club_info2 = htmlspecialchars($club_info);
	$sql_club_info = mysql_query
		("UPDATE members SET club_info='$club_info2' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">CLUB INFORMATION:</td>\n
			<td class=\"alert\" align=\"left\">$club_info</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Club Information:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($newsletter)) {
	$sql_newsletter = mysql_query
		("UPDATE members SET newsletter='$newsletter' WHERE member_name='$member_name'");
	echo "<tr>\n
			<td class=\"alert\" align=\"left\">NEWSLETTER:</td>\n
			<td class=\"alert\" align=\"left\">$newsletter</td>\n
		</tr>\n";
	} else {
		echo "<tr>\n
				<td align=\"left\">Newsletter:</td>\n
				<td align=\"left\" class=\"required\">WAS NOT CHANGED</td>\n
			</tr>\n";
}
if(isset($password)) {
$subject = "Password change on the Eureka Toastmasters Club website";
$message = "Hello, you have recently updated your password.  Here is your new login information:

	Your Username is: $member_name
	Your new password is: $password

You may use this password to login at http://www.rfwrangler.frih.net.


Thank you,
The Webmaster
The Eureka Toastmasters Club

This is an automated response, please DO NOT reply!";
	mail
($email_address, $subject, $message, "From: The Eureka Toastmasters Club Webmaster<noreply@rfwrangler.frih.net>
	n X-Mailer: PHP/" . phpversion());
	echo "<tr>\n
			<td colspan=\"2\" class=\"alert\" align=\"justify\">Your Username and NEW Password have been
			sent to your Email Address.&nbsp;&nbsp;Please check your email.</td>\n
		</tr>\n";
}
echo "</table>\n";*/
include 'Resources/HTML/error_include_registration.html';		
?>


#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 20 August 2006 - 02:01 AM

What exactly is the problem you are having?

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 20 August 2006 - 02:04 AM

Also you do realize a good majority of your code is commented out towards the end, right?

#4 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 20 August 2006 - 02:06 AM

Quick note - you can space/time by using this:
$password_new = stripslashes($_POST['password_new']);
As for the hanging problem try disabling sections bit by bit until it fails to hang. For example, disable that last include by commenting it and try it. If it still hangs uncomment it and disable something else.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#5 rfwrangler

rfwrangler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 20 August 2006 - 02:54 AM

Quick note - you can space/time by using this:

$password_new = stripslashes($_POST['password_new']);
As for the hanging problem try disabling sections bit by bit until it fails to hang. For example, disable that last include by commenting it and try it. If it still hangs uncomment it and disable something else.

Thank you no I didn't know that I could code it that way.  I am just learning PHP.  Thank you for the advice.

I don't know exactly where the problem is I have been trying to comment out different sections to fond the problem.  The include file works becuase I use it several other places in the site and in other PHP scripts that are working.

#6 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 20 August 2006 - 03:07 AM

First thing I'd do in debugging is disable any line that makes a change to the database so that you can use echo to show the contents of variables safely by running the script through with test data and see how its behaving.

You have a large section of the bottom half commented out so none of that is being called.  That leaves the routine to check for a password change.  Check all your variables and form labels for any typos but looking at what you have shown there I can't see any reason why it should be hanging! I suspect its hanging in one of the includes because of a variable in that script but I can't be sure.

Sorry I can't be of more help.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#7 rfwrangler

rfwrangler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 20 August 2006 - 04:23 AM

Thank you everyone for all of the help.  I found the problem the help with the debugging was the key.  I had a couple of typos in the script.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users