non case sensitive SQL query

Hey guys, I am working on a log in system for a project I am doing at school, but the username will only search case sensitive, I need it to be non case sensitive.

This is the code I have for the log in system:

[php]<?php
session_start();
//error_reporting(0);
if (isset($_SESSION[‘user’]))
{
die(header(“Location: index.php”));
}
else
{
//echo “Session = “.$_SESSION[‘user’].”
”;
if (isset($_POST[‘submit’]))
{
$username = $_POST[‘username’];
$password = $_POST[‘password’];

	mysql_connect("localhost","root","");
	mysql_select_db("3.46");
	$sql = "SELECT * FROM members WHERE UPPER(members.'Name') LIKE '%$username%'";
	//echo $sql;
	//echo "Searching for: $username<br/>";
	$members = mysql_query($sql);
	$count = mysql_num_rows($members);
	
	if ($count == 0)
	{
		echo "<b><p style='color: red'>Unable to find member: $username</p></b>";
	}
	else
	{
		while($row=mysql_fetch_array($members))
		{
			$dbpass = $row['Md5'];
			$dbuser = $row['Name'];
			//echo "<br/>dbuser = ".$dbuser;
			//echo "<br/>username = ".$username;
		}
		if ($username != $dbuser || sha1($password) != $dbpass)
		{
			if (sha1($password) != $dbpass)
			{
				echo "Incorrect password<br/>";
			}
		}
		else
		{	
			$_SESSION['user'] = $dbuser;
			//echo "<br/>Session: ".$_SESSION['user']."<br/>";
			//header("Location: index.php");
		}
	}
}

}
?>[/php]

Currently using that, it will not find any username, even if I type it correctly.
Does anybody have any idea what I am doing wrong and why it will not work?

Yes, I am aware that I am using Sha-1 encoding and the table row is Md5, the reason for this is that I was using Md5 at first and never got around to changing the table to Sha-1.

Fixed it:

I changed the statement that checks if user or pass is not the same as db to:
[php]if (strtoupper($username) != strtoupper($dbuser) || sha1($password) != $dbpass)
{
if (sha1($password) != $dbpass)
{
echo “Incorrect password
”;
}
if (strtoupper($username) != strtoupper($dbuser))
{
echo “Incorrect Username”;
}
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service