• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Login function

Bufo

-.-'
Joined
Jul 30, 2010
Messages
134
Reaction score
12
Location
P(R)OLAND
Hello I have problem with one function, when I wanna use this function, appears white site:

PHP:
function logIn()
	{
		if (!empty($login_account) && !empty($login_password)) {
			$query_login = $db->query("SELECT `accno`,`password` FROM `accounts` WHERE `accno` = '".$login_account."' AND `password` = '".$login_password."' LIMIT 1;");
			
			foreach($query_login as $login) {
				if($login == "Array") {
					echo "Login";
				} else {
					echo "Not login";
				}
			}else {
				echo "Not login";
			}
			break;
		}
	}

It's not problem with var becouse when I put in this someone account and password it's the same error.
PHP:
$login_account = '111111';
$login_password = 'tibia';

Anybody can help me ?

#Edit
This is also not a problem with query becouse when I put this query in myphpadmin:
Code:
SELECT `accno`,`password` FROM `accounts` WHERE `accno` = '".$login_account."' AND `password` = '".$login_password."' LIMIT 1
With any account and password, it's works
 
Last edited:
I also tried use something like this:
PHP:
    function logIn($login_account,$login_password)
       {
         $query_login = $db->query("SELECT `accno`,`password` FROM `accounts` WHERE `accno` = '".$login_account."' AND `password` = '".$login_password."' LIMIT 1;");

             foreach($query_login as $login) {
                if($login == "Array") {
                   echo "Login";
                } else {
                   echo "Not login";
                }
             }
          }

And same error, white page.
 
To stop getting a white screen and see the actual errors add this right before
PHP:
function logIn()

PHP:
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

If I had to guess your problem is that `$db` doesn't exist, so you'd get an error like "Fatal error: Call to a member function query() on a non-object"

You need to pass $db as a parameter, or create it like
PHP:
$db = new PDO('mysql:host=localhost;dbname=otserv', 'user', 'pass');

You also should not mix $login_account and $login_password with the query, instead use prepared statements.
 
Back
Top