Function with True / False return

From: Date: Tue, 23 Jan 2001 02:40:36 +0000
Subject: Function with True / False return
Groups: php.general 
Request: Send a blank email to php-general+get-36130@lists.php.net to get a copy of this message
can anyone tell me whats wrong with this function: function AuthenticateUser($user, $password) { global $DB_Server, $HTTP__Host, $DB_Login, $DB_Password, $DB_Name, $DocRoot ; // Open a connection with the MySQl server if (!($link = mysql_connect ($DB_Server,$DB_Login, $DB_Password))) { DisplayErrMessage(sprintf("internal error %s %s %s %d:%s\n",$DB_Server, $DB_Login, $DB_Password, mysql_errno(), mysql_error())); return 0 ; } // Do the user/password authentication via attempted update of stats if (!($result = mysql_db_query($DB_Name,"UPDATE users SET visits='4' WHERE user_id='$user' AND password='$password'"))) return 0; else return 1; } code that references the above function if (AuthenticateUser($form_user_id, $form_password)){ setcookie("cookie_passwd",$form_password); setcookie("cookie_user",$form_user_id); header("Location:http://$HTTP_Host/$DocRoot/default_authenticated.php"); exit(); } else { header("Location:http://$HTTP_Host/$DocRoot/error.php?type=badpass"); exit() ; } It's ment to test the validity of a login attempt with a user and passoword by updateing the colum visits to a new value. But weather or not this update passes or fails the return value seems to be 1 as the page is rediredted to the logged in page. Also can I update the visits value in the SQL command I've tried visits=visits+1 but that does not seem to work even though I have seen this done with a $variable instead of the value one. Any help would be appreciated. Jamie

« previous php.general (#36130) next »