Page 1 of 1

Help debugging login script?

Posted: Thu Dec 30, 2010 11:00 am
by Cucumberdude

Code: Select all

<?php
	//Retrieve form data
	$username = $_POST['username'];
	$password = $_POST['password'];
	
	//Access mySQL database to check the pass and user match
	$mySQL_password = "PASSWORD";
	$mySQL_username = "USERNAME";
	$mySQL_localhost = "HOST";
	
	$cnx = mysqli_connect($mySQL_localhost, $mySQL_username, $mySQL_password)
		or die("Error: could not connect to database!");
	
	$database = "sterli41_g4j";
	
	$dbselect = mysqli_select_db($cnx, $database)
		or die("Error: could not select database!");
		
	$query = "SELECT * FROM members";
	
	$result = mysqli_query($cnx, $query)
		or die(mySQL_error());
	
	$login = false;
	
	while ($row = mysql_fetch_array($result))
	{
		$pass = $row['password'];
		$user = $row['username'];
		
		if($user == $username)
		{
			if($pass == $password)
			{
				$login = true;
			}
		}
	}


	if ($login)
	{
		echo("LOGIN NOW");
	}
	else
	{
		echo("LOGIN FAILED!");
	}
	
	mysqli_close($cnx);
		
?>
That's the code for a login script. I get this:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in gamesforjunk/logincheck.php on line 26
LOGIN FAILED!
each time I try to log in, even if I use the correct pass/user combo.

Where am I going wrong?

Re: Help debugging login script?

Posted: Thu Dec 30, 2010 1:47 pm
by Technical
Because you're using MySQLi, you need mysqli_fetch_array() function.

Re: Help debugging login script?

Posted: Thu Dec 30, 2010 2:44 pm
by Cucumberdude
I feel dumb now >.<

Re: Help debugging login script?

Posted: Thu Dec 30, 2010 3:21 pm
by Technical
No pain, no gain