Nodral Posted June 20, 2011 Share Posted June 20, 2011 Hi I've written a bit of code to validate whether a user has typed into a password box by using if(strlen($password>0)){ // ok to save password. }else{ //give error message } However this is constntly saying the password is blank. Any ideas? My actual code follows below. I know that the $password variable is set as I've echoed it out as a test. <?php if(isset($_POST['pconf'])){ //has a password been entered? echo $password; if(strlen($password >0)){ //do new passwords match? if($pword===$password){ //encode pword $pword=md5($pword); //write to DB $sql="UPDATE pfp_user SET firstname = '$firstname', password = '$password', lastname = '$lastname', email = '$email', dept = '$dept', workplace = '$workplace' , home = '$home', complete = 'yes' WHERE id = " . $_SESSION['USERID']; mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); //redirect back to menu page $_SESSION['output']='Your user profile has been successfully updated'; $extra="menu.php"; header("Location: http://$host$uri/$extra"); }else{ $_SESSION['warning']="Please re-enter your passwords as they do not match"; $_POST['pass']=""; } }else{ $_SESSION['warning']="You cannot have a blank password<br>Please re-enter."; $_POST['pass']=""; } }else{ $sql="UPDATE pfp_user SET firstname = '$firstname', lastname = '$lastname', email = '$email', dept = '$dept', workplace = '$workplace' , home = '$home', complete = 'yes' WHERE id = " . $_SESSION['USERID']; mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); //redirect back to menu page $_SESSION['output']='Your user profile has been successfully updated'; $extra="menu.php"; header("Location: http://$host$uri/$extra");}?> Link to comment https://forums.phpfreaks.com/topic/239888-password-length-validation/ Share on other sites More sharing options...
trq Posted June 20, 2011 Share Posted June 20, 2011 Where do you actually define $password? Link to comment https://forums.phpfreaks.com/topic/239888-password-length-validation/#findComment-1232216 Share on other sites More sharing options...
Nodral Posted June 20, 2011 Author Share Posted June 20, 2011 $password comes from a form and I know it has value as I've echoed it out in the top of the code I posted, as a test. I didn't think you'd appreciate 200 lines of code being posted, so I just posted the relevant parts. It's not writing to the DB which indicates that the if(strlen() function has an error Link to comment https://forums.phpfreaks.com/topic/239888-password-length-validation/#findComment-1232220 Share on other sites More sharing options...
Nodral Posted June 20, 2011 Author Share Posted June 20, 2011 Sorted. The bracket was after the >0 instead of after $password Link to comment https://forums.phpfreaks.com/topic/239888-password-length-validation/#findComment-1232231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.