Irresistable Posted November 10, 2009 Share Posted November 10, 2009 I have a login form on my website. The register, and activation works perfect. When I try login with an activated account and right details I recieve these two errors; Warning: Missing argument 4 for Session::login(), called in /home/jeanie/public_html/process.php on line 37 and defined in /home/jeanie/public_html/include/session.php on line 88 Warning: mysql_fetch_array() [function.mysql-fetch-array]: The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH. in /home/jeanie/public_html/include/database.php on line 54 array(0) { } Here are the code snippets that you are most likely to need. Login Form <div class="twoColLiqRtHdr" id="login"> <?php if($session->logged_in) { echo'Welcome <strong>$session->username</strong>'; if($session->isAdmin) { echo'<a href="#">Admin</a>'; } } else { ?><br /> <form method="post" action="process.php"> <table width="500" border="0" id="login"> <tr> <td width="195"><br /></td> <td width="144"><input name="remember" type="checkbox" id="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?> /> Remember me </td> <td width="144">Forgotten your password?</td> <td width="49"><input type="hidden" name="sublogin" value="1" /></td> </tr> <tr> <td><? echo $form->error("activate"); ?></td> <td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>" /></td> <td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>" /></td> <td><input type="submit" value="Login" /></td> </tr> <tr> <td> </td> <td><? echo $form->error("user"); ?></td> <td><? echo $form->error("pass"); ?></td> <td> </td> </tr> </table> </form> <?php } ?> </div> Process.php <?php function procLogin(){ global $session, $form; /* Login attempt */ $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember'])); /* Login successful */ if($retval){ header("Location: index.php?user=$session->username"); } /* Login failed */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } }?> Session.php <?php function login($subuser, $subpass, $subremember, $activated){ global $database, $form; //The database and form object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Check if username is not alphanumeric */ if(!eregi("^([0-9a-z])*$", $subuser)){ $form->setError($field, "* Username not alphanumeric"); } } /* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Checks that username is in database and password is correct */ $subuser = stripslashes($subuser); $result = $database->confirmUserPass($subuser, md5($subpass), $activated); /* Check error codes */ if($result == 1){ $field = "user"; $form->setError($field, "* Username not found"); } else if($result == 2){ $field = "pass"; $form->setError($field, "* Invalid password"); } else if($result == 3){ $field = "activate"; $form->setError($field, "* Account not activated"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Username and password correct, register session variables */ $this->userinfo = $database->getUserInfo($subuser); $this->username = $_SESSION['username'] = $this->userinfo['username']; $this->userid = $_SESSION['userid'] = $this->userinfo['userid']; $this->activated = $_SESSION['activated'] = $this->userinfo['activated']; $this->userlevel = $this->userinfo['userlevel']; /* Insert userid into database and update active users table */ $database->addActiveUser($this->username, $this->time); $database->removeActiveGuest($_SERVER['REMOTE_ADDR']); if($subremember){ setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH); setcookie("cookpass", $this->password, time()+COOKIE_EXPIRE, COOKIE_PATH); setcookie("cookact", $this->activated, time()+COOKIE_EXPIRE, COOKIE_PATH); setcookie("cookid", $this->userid, time()+COOKIE_EXPIRE, COOKIE_PATH); } /* Login completed successfully */ return true; }?> Database.php <?php function confirmUserPass($username, $password, $activated){ /* Add slashes if necessary (for query) */ if(!get_magic_quotes_gpc()) { $username = addslashes($username); } /* Verify that user is in database */ $q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'"; $result = mysql_query($q, $this->connection); if(!$result || (mysql_numrows($result) < 1)){ return 1; //Indicates username failure } /* Retrieve password from result, strip slashes */ $dbarray = mysql_fetch_array($result); $dbarray['password'] = stripslashes($dbarray['password']); $password = stripslashes($password); /* Validate that password is correct */ if($password != $dbarray['password']){ return 2; /* indicates password failure */ } /* Checks if user is activated */ $results = mysql_query("SELECT activated FROM ".TBL_USERS." WHERE username = '$username' LIMIT 1"); $row = mysql_fetch_array($results, $this->connection); var_dump($row); if($row['activated'] == 1) { return 3; /* indicates user not activated */ } else { return 0; /* user logged in successfully */ } }?> What it's suppose to do, is check if the username and password in the database and are correct, also checks to see if there account is activated or not. (Not activated = 1, activated = 2) If it does not meet any of these requirements, it will show up the error fields. Also sets a cookie for the remember me feature. Though I recieve the errors posted right at the top of this post. Can you help? Thanks Link to comment https://forums.phpfreaks.com/topic/181036-major-issues-trying-to-log-in/ Share on other sites More sharing options...
trq Posted November 10, 2009 Share Posted November 10, 2009 The error is pretty self explanatory. Your missing the 4th argument to login(). Link to comment https://forums.phpfreaks.com/topic/181036-major-issues-trying-to-log-in/#findComment-955177 Share on other sites More sharing options...
Irresistable Posted November 10, 2009 Author Share Posted November 10, 2009 Yes, I thought that. So it'd be.. $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']) $_POST['activated']); But what I don't understand is.. it's not posting activate. Though if you think its correct I take your word.. What about the second error? I've tried "mysql_real_assoc" Though with assoc, I recieve this error.. Warning: Wrong parameter count for mysql_fetch_assoc() in /home/jeanie/public_html/include/database.php on line 54 NULL So I'm not sure what to do. Can you help me with this? Link to comment https://forums.phpfreaks.com/topic/181036-major-issues-trying-to-log-in/#findComment-955187 Share on other sites More sharing options...
Irresistable Posted November 10, 2009 Author Share Posted November 10, 2009 Does anybody know what I have to do? Link to comment https://forums.phpfreaks.com/topic/181036-major-issues-trying-to-log-in/#findComment-955228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.