fer0an Posted July 9, 2011 Share Posted July 9, 2011 hello I've query that find duplicate entry on my website. I want add entry if it's not duplicate else continue next entry. this is my code but when finding duplicate stoped and write cannot fronted. if($result5_f = mysql_query($query5_f) ) echo "fronted"; else die(mysql_error()."cannot fronted"); please help me Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/ Share on other sites More sharing options...
sanfly Posted July 9, 2011 Share Posted July 9, 2011 My first hint would be to check out the Comparison Operators in the PHP manual in your if statement comparison you should have == not = Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240504 Share on other sites More sharing options...
Andy11548 Posted July 9, 2011 Share Posted July 9, 2011 I personally love my curly brackets, so if what he said doesn't work, try: if($result5_f == mysql_query($query5_f)) { echo "fronted"; } else { die(mysql_error()."cannot fronted"); } Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240514 Share on other sites More sharing options...
sanfly Posted July 9, 2011 Share Posted July 9, 2011 Im also a big fan of curly brackets, and wasn't sure the code would work without them, so I did a little test <?php $br = "breeze"; if($br == "breeze") echo "its a breeze"; else echo "not so easy"; ?> and the result was "its a breeze" so while I agree curly brackets are probably best practice, they don't appear to be necessary Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240515 Share on other sites More sharing options...
Andy11548 Posted July 9, 2011 Share Posted July 9, 2011 I say use them for the fact it makes your code easier to read in my opinion. However, I'm still a newbie at PHP, so, that could be why I find it easier, haha . Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240529 Share on other sites More sharing options...
jcbones Posted July 9, 2011 Share Posted July 9, 2011 Curly brackets are not required IF the if/else statement only has one line following it. I am a fan of using them at all times. That being said, I'm not sure if this line of code does what you want it to: $result5_f == mysql_query($query5_f) As mysql_query() returns a result resource, and not the actual data. It would help you understand this better, if you ran this line: echo mysql_query($query5_f); Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240536 Share on other sites More sharing options...
sanfly Posted July 9, 2011 Share Posted July 9, 2011 Its been so long since Ive coded proper PHP (I've been using CakePHP for a few years now) I can hardly remember how the database calls go. Perhaps something like (hope my syntax is correct) <?php $r1 = mysql_query("SELECT * FROM tablename WHERE fieldname == '$comparison_value'"); if(mysql_num_rows($r1) > 0){ echo "its a duplicate"; } else{ echo "its unique"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240657 Share on other sites More sharing options...
jcbones Posted July 10, 2011 Share Posted July 10, 2011 cakePHP is nice, but like learning a whole new language. Def. makes for faster coding though. Yes, that is one way of doing it. Quote Link to comment https://forums.phpfreaks.com/topic/241492-if-else/#findComment-1240734 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.