Jump to content


Photo

Updating isn't working???


  • Please log in to reply
3 replies to this topic

#1 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 25 October 2006 - 12:31 AM

I am wanting a user to login to view their account and to be able to edit their details. When I click on the save button it makes the information that I have placed in the text boxes disappear not including what is already in the database. Can someone please tell me why this happening and how I can fix? Thanks in advance.

Here is the code to save the details:
require "config2.php";
// the save button
if (isset($_POST['save'])) {
$arrErrors = array();
// get the email address
$email = $_POST['email'];
// get the current password
$currentpassword = $_POST['currentpassword'];
// get the new password
$newpassword = $_POST['newpassword'];
// get the second password
$newpassword2 = $_POST['newpassword2'];

if ($email == '') {
	$arrErrors['email'] = 'You have deleted the email address please refresh the page to display the email address again.';
}
if (strlen($currentpassword) < 6) {
	$arrErrors['currentpassword'] = 'Please enter a password that is 6 or more characters in length.';
}
if ((strlen($newpassword) > 6) AND ($newpassword2 == '')){
	$arrErrors['newpassword2'] = 'Please enter the password again in the confirm new password field.';
}

if (count($arrErrors) == 0) {	
	$username = mysql_real_escape_string($_COOKIE['username']);
	$email = mysql_real_escape_string($_POST['email']);
	$email2 = mysql_real_escape_string($_POST['email2']);
	$currentpassword = mysql_real_escape_string($_POST['currentpassword']);
	$newpassword = mysql_real_escape_string($_POST['newpassword']);
	$newpassword2 = mysql_real_escape_string($_POST['newpassword2']);
	
	$update = "UPDATE `users` SET `password` = '$newpassword', `email` = '$email2' WHERE `username` = '$username'";
		if (mysql_query($update)) {
			header ('Location: updated.php');
		} else {			
			print "Could not add the entry because: " . mysql_error() . ". The query was $update.";
		}
} else {
        // The error array had something in it. There was an error.
        // Start adding error text to an error string.
        $strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
        // Get each error and add it to the error string
        // as a list item.
        foreach ($arrErrors as $error) {
            $strError .= "<li>$error</li>";
        }
        $strError .= '</ul></div>';
    }
mysql_close();
}

Here is the code to display the my account:
<form name="myaccountform" method="post" action="<?php echo $PHP_SELF; ?>">
<?php
require "config2.php";
$username = mysql_real_escape_string($_COOKIE['username']);
$query = "SELECT * FROM `users` WHERE `username` = '$username'";
$result = mysql_query ($query) or die("Could not query because: " . mysql_error());
while($row = mysql_fetch_array($result)){
echo "<div align=left><table width=50%><tr><td>Username:</td><td>".$row['username']."</td></tr><tr><td>E-mail address:</td><td>";
echo "<input name=email type=text value=".$row['email']."></td></tr><tr><td>New e-mail address:</td><td><input name=email2 type=text value=".$row['email2']."></td></tr><tr><td>Current password:</td><td><input name=currentpassword type=password></td></tr><tr><td>New password:</td><td><input name=newpassword type=password></td></tr><tr><td>Confirm new password:</td><td><input name=newpassword2 type=password></td></tr><tr><td colspan=2></td></tr></table></div>";
}
mysql_close();


#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 25 October 2006 - 03:05 AM

It's possible that your update query succeeds but affects 0 rows (that is, nothing was updated).  You can try keeping the result of the query, then calling mysql_affected_rows($result) to see how many rows were updated.

#3 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 25 October 2006 - 04:25 AM

I have tried that and now I am getting this error: Warning: mysql_affected_rows(): supplied resource is not a valid MySQL-Link resource in /home/account/public_html/folder/folder/my account.php on line 109.

#4 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 25 October 2006 - 04:27 AM

Sorry I have worked out why I getting that error. I put it in the wrong place.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users