Forum Moderators: coopster

Message Too Old, No Replies

PHP-Mysql - Issues with username checking function.

getting this error: Warning: implode() [function.implode]: Bad arguments.

         

GamingLoft

11:42 pm on Feb 5, 2008 (gmt 0)

10+ Year Member



i have been having some problems with my username checking function and i have no idea why this is happening any soulutions to my errors would be great.

i get this error when running my name checker...

"
Warning: implode() [function.implode]: Bad arguments. in /home/EXAMPLE/public_html/EXAMPLE/namea.php on line 11"
"

here is my username check function..

function checkUsername($username)
{
if (eregi('^[[:alnum:]\.\?\!\-\_\'\-]{4,12}$', stripslashes(trim($username)) )) {//must be 4-12 letters/chars long .?! - _ ' all aloud + nums and letters
$user = mysql_real_escape_string($username);
$query_usernamecheck = "SELECT username FROM hfs_users WHERE username = '$username'";
$result = @mysql_query($query_usernamecheck);
$num_samename = @mysql_num_rows($result_usernamecheck);
if ($num_samename> 0) { //checks if anyone is using this nam
$errors[] = "This name is not availible.";//error message if someones using name
}
else {
$user = mysql_real_escape_string($username);
$query_blockedname = "SELECT username FROM hfs_blockedname WHERE username = '$username'";
$result_blockedname = @mysql_query($query_blockedname);
$num_blockedname = @mysql_num_rows($result_usernamecheck);
if ($num_blockedname> 0) {
$errors[] = "The username you entered is not aloud.";//error message if name is put in unacceptable list
}
else{
$check= eregi("slime¦kille[rd]¦puke¦vomit¦suck¦spastic¦spaz¦(you )¦( you )¦(u )¦( u )¦( of?f$)¦( of?f )¦[asz]{3,}", $intext);
if ($check) {
$errors[] = "Usernames are not aloud to contain foul language.";
} else { return FALSE;
}}}}
else {
$errors[] = "You're username must contain only letters, numbers and the following characters: .?! - _";
}
if(!empty($errors)){ return $errors; }
return true;
}

here is my name checking file...

<?php
include("mysql_connect.php");
include("functions.php");
$urlname = $_GET['name'];
if(($rslt = checkUsername($urlname)) === true)
{
echo 'Its all good.';
}
else
{
echo implode('<br />', $rslt);
}
?>

eelixduppy

12:11 am on Feb 6, 2008 (gmt 0)



implode can only take an array as the second parameter. If your function returns anything else, it will give you the error that you are receiving. You already account for it returning TRUE, but you have failed to check to see if the function is returning FALSE. If it returns FALSE OR and array it will try to implode it, but we know that you cannot implode FALSE.

This is where your error is coming from.

GamingLoft

12:46 am on Feb 6, 2008 (gmt 0)

10+ Year Member



isn't the if... === true) where the function is checked to be false or true?

idk, i hardly understand what you're saying.

eelixduppy

12:47 am on Feb 6, 2008 (gmt 0)



yes, but it only checks for the true case. If it's false it will go into the else statement, therefore trying to implode an "invalid argument" :)

GamingLoft

12:49 am on Feb 6, 2008 (gmt 0)

10+ Year Member



so should i use a else if ... = false?, or what?

actually i fixed my problem by flipping around the true and falses, thanks for the help.

[edited by: GamingLoft at 12:52 am (utc) on Feb. 6, 2008]