Help - Search - Members - Calendar
Full Version: Php Warning, Query Did Not Work Mysql_fetch_array()
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
griffo
Hi, below is snippet of code for registration, every thing works ok, however i get --- Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in---

at the check where we check if user already exists...

i no its a query issue however is this a common error? and is there a quick solution...
*------------------------------------------------------------------------------------------------------------
function checkUser() {
$connection = connectDB();
$check = "SELECT * FROM users WHERE user_name = $username";
$result2 = @mysql_query($check, $connection);
$item = array();
while ($row = mysql_fetch_array($result)) {
$item[] = $row;
}
disconnectDB($connection);

return $item;
}


//error checking
if (empty($fname) || empty($pass1) || empty($pass2) || empty($usertype) || empty($DOB) || empty($email) || empty($sex) || empty($lname) || empty($username)) {
header("Location: fields-missing.html");
exit;

}
checkUser();

if ($pass1 != $pass2) {
header("Location: pass-nomatch.html");
exit;

} else if ($item[0] == null) {
header("Location: already-exists.html");
echo $item[0];
exit;

} else {
addUser($fname, $lname, $username, $pass1, $usertype, $DOB, $email, $sex);
// Email password and login for register-exec
header("Location: index.html");
}
swordz
CODE
function checkUser() {
    $connection = connectDB();
    $check = "SELECT * FROM users WHERE user_name = $username";
    $result2 = @mysql_query($check, $connection);
    $item = array();
    while ($row = mysql_fetch_array($result)) {
        $item[] = $row;
    }
    disconnectDB($connection);
    
    return $item;
    }


You're defining $result2, then using $result.

Swordz
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.