almightyegg Posted December 24, 2007 Share Posted December 24, 2007 I have an IF like so: if($info1[amount] < $input1 && $item1 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; } and with the variables I've set it should echo it out but it doesn't. $info1[amount] = 472 $input1 = 500 $item1 = dappp Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/ Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 it should be like this: if($info1['amount'] < $input1 && $item1 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; } $info1['amount'] = 472 Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422609 Share on other sites More sharing options...
almightyegg Posted December 24, 2007 Author Share Posted December 24, 2007 No change... Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422611 Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 does the script echo any errors? or does it just do nothing? Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422612 Share on other sites More sharing options...
almightyegg Posted December 24, 2007 Author Share Posted December 24, 2007 I'll post the whole script: if($count1 != 1 && $item1 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($count2 != 1 && $item2 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($count3 != 1 && $item3 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($count4 != 1 && $item4 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($count5 != 1 && $item5 != 0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif(!$item1 && !$item2 && !$item3 && !$item4 && !$item5){ echo "You didn't select any items to donate!"; }elseif($info1['amount'] < $input1 && $item1 != 0){ // IT SHOULD STOP HERE echo "You don't have enough of at least one of the items you wanted to give."; }elseif($info2['amount']<$input2 && $item2!=0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($info3['amount']<$input3 && $item3!=0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($info4['amount']<$input4 && $item4!=0){ echo "You don't have enough of at least one of the items you wanted to give."; }elseif($info5['amount']<$input5 && $item5!=0){ echo "You don't have enough of at least one of the items you wanted to give."; }else{ if(count($no_zero) == count(array_unique($no_zero))){ // IT ENDS HERE }else{ echo "You selected the same item more than once!"; } } I added tags to show what happens Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422614 Share on other sites More sharing options...
raku Posted December 24, 2007 Share Posted December 24, 2007 Try this: if($info1['amount'] < $input1 && $item1 !== 0){ echo "You don't have enough of at least one of the items you wanted to give."; } Note the "!==". Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422617 Share on other sites More sharing options...
almightyegg Posted December 24, 2007 Author Share Posted December 24, 2007 Now it won't stop echoing that error message out, no matter what value the tings are Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422620 Share on other sites More sharing options...
raku Posted December 24, 2007 Share Posted December 24, 2007 I think your problem here is that you're comparing a string to an integer. You might want to try putting quotes around the 0, but I'm not sure if that's what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422621 Share on other sites More sharing options...
almightyegg Posted December 24, 2007 Author Share Posted December 24, 2007 Ah great that worked! cheers Quote Link to comment https://forums.phpfreaks.com/topic/83075-solved-ifand-else-problems/#findComment-422622 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.