cturner Posted October 21, 2006 Share Posted October 21, 2006 An error is suppose to display when a user has deleted their email address and all it is displaying when that happens is class="formerror". Can someone please tell me why this is happening and how I can fix it? Thanks in advance.Here is the code for checking to see if the save button has been pressed:[code]$arrErrors = array();// the save buttonif (isset($_POST['save'])) {// get the email address$email = $_POST['email'];// get the current password$currentpassword = $_POST['currentpassword'];// get the new password$newpassword = $_POST['newpassword'];// get the $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']); $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 `email` = '$email', `password` = '$newpassword' WHERE `username` = '$username'"; if (mysql_query($update)) { header ('Location: updated.php'); } else { print "Could not add the entry because: " . mysql_error() . ". The query was $result."; }} 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>'; }}[/code]Here is the code for displaying the form:[code]require "config2.php";// get the username$username = $_COOKIE['username'];?><br><form name="myaccountform" method="post" action="<?php echo $PHP_SELF; ?>"><?php$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>";if (!empty($arrErrors['email'])) echo ' class="formerror"'; echo "<input name=email type=text value=".$row['email']."></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();[/code] Quote Link to comment Share on other sites More sharing options...
Jocka Posted October 21, 2006 Share Posted October 21, 2006 well the if statement all calls for ' class="formerror"'See for yourself (in form):if (!empty($arrErrors['email'])) echo ' class="formerror"';What would work maybe is:[code]<?phpif (!empty($arrErrors['email'])) {// echo ' class="formerror"'; // //^- i don't know what this is but it needs // to be in a field somewhere.echo "<input name=email type=text value=".$row['email']."></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>";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.