Jump to content

Touble with PHP Script


rfwrangler

Recommended Posts

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:
[code]<?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';
?>[/code]
Link to comment
Share on other sites

Quick note - you can space/time by using this:
[code]$password_new = stripslashes($_POST['password_new']);[/code]
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.
Link to comment
Share on other sites

[quote author=Yesideez link=topic=104908.msg418751#msg418751 date=1156039612]
Quick note - you can space/time by using this:
[code]$password_new = stripslashes($_POST['password_new']);[/code]
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.
[/quote]
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.
Link to comment
Share on other sites

First thing I'd do in debugging is disable any line that makes a change to the database so that you can use [b]echo[/b] 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 [i]suspect[/i] 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.
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.