LooieENG Posted September 5, 2008 Share Posted September 5, 2008 I entered test on the form $username = mysql_real_escape_string(trim($_POST['username'])); exit($username); Returns test $username = mysql_real_escape_string(trim($_POST['username'])); exit(strlen($username)); Returns nothing Link to comment https://forums.phpfreaks.com/topic/122922-solved-strlen-not-working/ Share on other sites More sharing options...
kratsg Posted September 5, 2008 Share Posted September 5, 2008 strlen() returns an integer, and when you pass an integer inside the exit() function, rather than echoing it, the integer acts as a "status". Certain integers have error codes with them, and so by passing the error code # into the exit, it will display the error associated with it. Just use die(strlen($username)); instead. And checking php.net confirms what I've said: Description void exit ([ string $status ] ) void exit ( int $status ) Terminates execution of the script. Parameters status If status is a string, this function prints the status just before exiting. If status is an integer, that value will also be used as the exit status. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully. Note: PHP >= 4.2.0 does NOT print the status if it is an integer. Link to comment https://forums.phpfreaks.com/topic/122922-solved-strlen-not-working/#findComment-634847 Share on other sites More sharing options...
LooieENG Posted September 5, 2008 Author Share Posted September 5, 2008 Thanks for the reply, the reason I'm using it in exit is because when I enter test this code always returns Username must have between 4 and 30 characters. This is my code <?php require('includes/config.php'); if ($_POST['register']) { $username = mysql_real_escape_string(trim($_POST['username'])); exit(strlen($username)); $password = trim($_POST['password']); $password2 = trim($_POST['password2']); if ((strlen($username) > 4) && (strlen($username) < 30)) { if ($password == $password2) { if (strlen($password) > { $password = md5($salt . $_POST['password']); mysql_query("INSERT INTO users ('username', 'password') VALUES ('$username', '$password')"); $info = 'Your account has been registered, you may now log in.'; include('includes/info.php'); exit; } else { $info = 'Your password must contain at least 8 characters.'; include('includes/info.php'); exit; } } else { $info = 'Your passwords didn\'t match, please try again.'; include('includes/info.php'); exit; } } else { $info = 'Username must have between 4 and 30 characters.'; include('includes/info.php'); exit; } } else { include('includes/register.php'); } ?> Edit: Just figured out 4 isn't more than 4 Thanks for the reply and explanation kratsg Link to comment https://forums.phpfreaks.com/topic/122922-solved-strlen-not-working/#findComment-634852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.