EffakT Posted April 20, 2013 Share Posted April 20, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/277169-non-case-sensitive-sql-query/ Share on other sites More sharing options...
requinix Posted April 20, 2013 Share Posted April 20, 2013 What does a SHOW CREATE TABLE members query output? Quote Link to comment https://forums.phpfreaks.com/topic/277169-non-case-sensitive-sql-query/#findComment-1425918 Share on other sites More sharing options...
EffakT Posted April 20, 2013 Author Share Posted April 20, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/277169-non-case-sensitive-sql-query/#findComment-1425923 Share on other sites More sharing options...
requinix Posted April 20, 2013 Share Posted April 20, 2013 You sure it's not already case-insensitive? Quote Link to comment https://forums.phpfreaks.com/topic/277169-non-case-sensitive-sql-query/#findComment-1425928 Share on other sites More sharing options...
EffakT Posted April 20, 2013 Author Share Posted April 20, 2013 I'm not sure, its not returning errors but it isn't setting the $_SESSION['user'] if i type the username case-insensitive. Quote Link to comment https://forums.phpfreaks.com/topic/277169-non-case-sensitive-sql-query/#findComment-1425932 Share on other sites More sharing options...
Solution EffakT Posted April 20, 2013 Author Solution Share Posted April 20, 2013 (edited) 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 April 20, 2013 by EffakT Quote Link to comment https://forums.phpfreaks.com/topic/277169-non-case-sensitive-sql-query/#findComment-1425935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.