Jump to content

if, else if, else


westman
 Share

Recommended Posts

my code is not working and i believe it is due to "if, else if, else"if ($pass1 != ""){ if ($pass1 != $pass2) { $updatmsg = '<font color="#FF0000" size="+1"><u>ERROR:</u><br />Your Password fields below do not match.<br /></font>'; }if (strlen($pass1) > 20) { $updatmsg = '<font color="#FF0000" size="+1"><u>ERROR:</u><br />Your New Password is too long. 6 - 20 characters please.<br /></font>'; }else{if (strlen($pass1) < 6) { $updatmsg = '<font color="#FF0000" size="+1"><u>ERROR:</u><br />Your New Password is too short. 6 - 20 characters please.<br /></font>'; }else$sql = mysql_query("UPDATE project SET password='$pass1' WHERE id='$id'")or die (mysql_error());$updatmsg = '<font color="#006600" size="+1">Your password was updated successfully.</font>';could you please help with a working scriptthank you.

Edited by westman
Link to comment
Share on other sites

So, what would you like to implement? The $pass1 value to be not empty AND different from $pass2 value AND with more than 20 characters AT THE SAME TIME? Or you need to check them individualy?(sorry for caps but I want to point the difference tha will help in development). if you want them simultaneously then you should do something like this:

if (($pass1=="") && ($pass1!=$pass2) && (strlen($pass1) > 20))   echo "ERROR!";

Another way is to use the 'if' and 'elseif':

if ($pass1=="") {echo "Empty field";} elseif ($pass1 != $pass2) {$updatmsg = '<font color="#FF0000" size="+1"><u>ERROR:</u><br />Your Password fields below do not match.<br /></font>'; } elseif (strlen($pass1) > 20) {$updatmsg = '<font color="#FF0000" size="+1"><u>ERROR:</u><br />Your New Password is too long. 6 - 20 characters please.<br /></font>'; } elseif (strlen($pass1) < 6) {$updatmsg = '<font color="#FF0000" size="+1"><u>ERROR:</u><br />Your New Password is too short. 6 - 20 characters please.<br /></font>'; } else {$sql = mysql_query("UPDATE project SET password='$pass1' WHERE id='$id'")or die (mysql_error());$updatmsg = '<font color="#006600" size="+1">Your password was updated successfully.</font>';}

I didn't test/check the code as I don't have any appropriate IDE and PHP installed on my PC. Just put the code in Netbeans or Eclispe to check for errors. Then, check the error console of your browser and post any error here. Also, you can use javascript for that operation.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...