monkeybidz Posted September 30, 2007 Share Posted September 30, 2007 Heres the deal i am working with: if(empty($miles) || !$miles) { $msg[] = $error8; } This code is in a form results page. But when i get the results for $miles as empty, it will ignore the error. This is used in a zip code distance calculator that i am working on. When two zip codes are entered, the miles between both are displayed based on latitude and longitude of the two. Some new zip codes are not present in the database since the database is old. When the zip is present in database, but latitude and longitude are not they return nothing(blank). The question here is what do i use for question: if $miles does not exsist return error: is it !$miles? Quote Link to comment https://forums.phpfreaks.com/topic/71228-empty-or-missing-variable/ Share on other sites More sharing options...
jd2007 Posted September 30, 2007 Share Posted September 30, 2007 try this...just use empty($miles), remove !$miles...so u get: if (empty($miles)) { $msg[] = $error8; } Quote Link to comment https://forums.phpfreaks.com/topic/71228-empty-or-missing-variable/#findComment-358285 Share on other sites More sharing options...
monkeybidz Posted September 30, 2007 Author Share Posted September 30, 2007 I found the problem: $msg[] had an e at the end like this $msge[]. Reminder: Don't Drink & Code! Thanks for the quick response. Quote Link to comment https://forums.phpfreaks.com/topic/71228-empty-or-missing-variable/#findComment-358573 Share on other sites More sharing options...
monkeybidz Posted October 1, 2007 Author Share Posted October 1, 2007 Ok, thought it was solved, but guess not. This is for a mileage calculator based on zip codes. If you are calculating the distance between two zip codes that are the same i get 0 miles which is fine, but when the zip does not exsist in database it comes back empty. By me adding this message for empty, i also get it when miles = 0. The code is reading 0 as empty, but i need the 0 to not be interpreted as empty, but as an actual result. Is there a way i can say if miles (another word for empty) then use error. Can it be done? if (empty($miles)) { $msg[] = $error8; } Quote Link to comment https://forums.phpfreaks.com/topic/71228-empty-or-missing-variable/#findComment-358813 Share on other sites More sharing options...
monkeybidz Posted October 2, 2007 Author Share Posted October 2, 2007 Ok. I found this article on the net and it seems to be my problem. I am using a newer version of PHP.: empty("0") The perhaps most cotroversal change in behavior has happend to the behavior of the empty(). A String containing only the character '0' (zero) is now considered empty while it wasn't in PHP 3.0. This new behavior makes sense in web applications, with all input fields returning strings even if numeric input is requested, and with PHP's capabilities of automatic type conversion. But on the other had it might break your code in a rather subtle way, leading to misbehavior that is hard to track down if you do not know about what to look for. Is there anything i can do beside downgrade PHP? Quote Link to comment https://forums.phpfreaks.com/topic/71228-empty-or-missing-variable/#findComment-359874 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.