CoffeeAddict Posted February 22, 2013 Share Posted February 22, 2013 Below is the code I'm trying to use, it works perfectly IF the color in the database is listed as "blue_merle". Problem being, it is not, it's listed as "Blue Merle". How can I make this continue to work without having to change the way the color is listed in the database? If I put "Blue Merle" in the php code then it just causes an error because of the space between the words. Help please? I feel like this is probably really simple to fix but it's going right over my head. else if ($dog1->color == blue_merle && $dog2->color == blue_merle) { echo '<p>You cannot breed two merles.</p>'; Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/ Share on other sites More sharing options...
Barand Posted February 22, 2013 Share Posted February 22, 2013 String values should be in quotes else if ($dog1->color == 'blue_merle' && $dog2->color == 'blue_merle') { echo '<p>You cannot breed two merles.</p>'; Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/#findComment-1414229 Share on other sites More sharing options...
CoffeeAddict Posted February 22, 2013 Author Share Posted February 22, 2013 Thanks! I just tried that and it still lets me breed two merles together when it should be throwing the echo message Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/#findComment-1414234 Share on other sites More sharing options...
Barand Posted February 22, 2013 Share Posted February 22, 2013 What do $dog1->color and $dog2->color contain? Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/#findComment-1414237 Share on other sites More sharing options...
CoffeeAddict Posted February 22, 2013 Author Share Posted February 22, 2013 They are both listed as Blue Merle. With the space. If I change them to blue_merle with the underscore, it works. But I'd like to avoid having to change it. Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/#findComment-1414239 Share on other sites More sharing options...
Jessica Posted February 22, 2013 Share Posted February 22, 2013 If the database says "Blue Merle", you need to compare to "Blue Merle", not 'blue_merle'. *smh* Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/#findComment-1414240 Share on other sites More sharing options...
CoffeeAddict Posted February 22, 2013 Author Share Posted February 22, 2013 Got it, tried it with the quotes and no space, but forgot to capitalize the words! Works great now. Thank you! Link to comment https://forums.phpfreaks.com/topic/274831-space-between-words-in-database-causing-error/#findComment-1414242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.