ngreenwood6 Posted July 31, 2008 Share Posted July 31, 2008 First let me explain what is happening. A user has input data into a database. I was trying to have this data pulled back up and have it displayed. I have created a few rules. If the user doesnt put anything in, it asks them to. if it doesnt match anything tell them there are no results. the problem is that as i am testing this i put in a capital letter as the first letter and it wont find it. I have to search by using a capital. This is the part that tells it to match it (elseif ($get_lastname != $lastname)). Does anyone know how I can make it none case sensitive. Here is my code: <?php //include variables include ("variables.php"); //include the database variables include ("db.php"); $mysql_connect = mysqli_connect($host,$db_username,$db_password,$db_name) or die ("Could not connect to database"); //variable to send data to the database $result = mysqli_query($mysql_connect,$getfrom_db) or die ("Error: ".mysqli_error($cxn)); $row = mysqli_fetch_array($result); $firstname = $row['firstname']; $lastname = $row['lastname']; $id = $row['id']; if (!$get_lastname) { include ("index.php"); echo ("Please enter a last name!"); } elseif ($get_lastname != $lastname) { echo ("There are no results, please enter a different last name!"); } else { echo ("$firstname $lastname your user id is $id!"); } ?> Thanks for all your help. Great community Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/ Share on other sites More sharing options...
ikmyer Posted July 31, 2008 Share Posted July 31, 2008 is the name in the database always going to be lower case ? if so... http://us3.php.net/manual/en/function.strtolower.php <?php elseif (strtolower($get_lastname) != $lastname) ?> Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/#findComment-604666 Share on other sites More sharing options...
JD* Posted July 31, 2008 Share Posted July 31, 2008 Will there be a difference if you convert your string to all lowercase? Like so: elseif(strtolower($get_lastname) != strtolower($lastname)) Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/#findComment-604667 Share on other sites More sharing options...
ngreenwood6 Posted July 31, 2008 Author Share Posted July 31, 2008 Thats the problem. the users will probably enter their name in capitols but when searching I want it to just check it for both. your suggestion worked though but will it work in all cases. Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/#findComment-604670 Share on other sites More sharing options...
ikmyer Posted July 31, 2008 Share Posted July 31, 2008 JD*'s code will always work... it changes both strings to all lower case then compares them Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/#findComment-604694 Share on other sites More sharing options...
ngreenwood6 Posted July 31, 2008 Author Share Posted July 31, 2008 Thanks for all your help! Like I said this is a great community! Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/#findComment-604700 Share on other sites More sharing options...
discomatt Posted July 31, 2008 Share Posted July 31, 2008 I don't see where you're performing the actual query... but you can always do with with MySQL alone SELECT `whatever` FROM `table` WHERE `name` LIKE 'a%' Will search for names that start with an A or a Check out more on the LIKE syntax here http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html Link to comment https://forums.phpfreaks.com/topic/117565-solved-case-sensitive/#findComment-604791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.