Jump to content

Non case-sensitive SQL query


EffakT
Go to solution Solved by EffakT,

Recommended Posts

Hey, I am currently working on a website for school and I am doing the Log in system. I need the 'Name' to be non-case sensitive.

How would I go about doing this?

The code I have so far is:

<?php
session_start();
//error_reporting(0);
if (isset($_SESSION['user']))
{
	die(header("Location: index.php"));
}
else
{
	//echo "Session = ".$_SESSION['user']."<br/>";
	if (isset($_POST['submit']))
	{
		$username = $_POST['username'];
		$password = $_POST['password'];
		
		mysql_connect("localhost","root","");
		mysql_select_db("3.46");
		$sql = "SELECT * FROM members WHERE Name = '$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");
			}
		}
	}
}
?>

What do I need to do the make the 'Name' non case-sensitive?

Link to comment
Share on other sites

CREATE TABLE `members` (
 `ID` int(11) NOT NULL AUTO_INCREMENT,
 `Name` varchar(80) NOT NULL,
 `Md5` text NOT NULL,
 `Email` varchar(80) NOT NULL,
 `Admin` int(1) NOT NULL DEFAULT '0',
 PRIMARY KEY (`ID`),
 UNIQUE KEY `ID` (`ID`),
 UNIQUE KEY `Name` (`Name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1

Link to comment
Share on other sites

  • Solution

Arrgh simple fix but I didn't even realize

 

To fix it, I changed the statement that checks if user or pass is not the same as db to:

if (strtoupper($username) != strtoupper($dbuser) || sha1($password) != $dbpass)
			{
				if (sha1($password) != $dbpass)
				{
					echo "Incorrect password<br/>";
				}
				if (strtoupper($username) != strtoupper($dbuser))
				{
					echo "Incorrect Username";
				}
			}
Edited by EffakT
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.