The Little Guy Posted January 23, 2008 Share Posted January 23, 2008 <?php if(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; } if(!is_int($page)){ $page = 1; } ?> OK... If I take the above code and use it... It works if $_GET['page'] == 1 But if $_GET['page'] == cat it doesn't work. Error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20, 20' at line 3 cat makes -20 1 make 0 Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/ Share on other sites More sharing options...
cooldude832 Posted January 23, 2008 Share Posted January 23, 2008 so I take it you are trying to get a pagination number? best method is this <?php //Return Max number of pages allowed in pagination if(intval($_GET['page']) > 0 && $intval $_GET['page'] <= $max_pages({ $page = intval($_GET['page']); } else{ $page = 1; } ?> amend to this if you use 0 - 1-max pages for your range. Also check your register globals as $page and $_GET['page'] are the same variable in terms of register_globals on Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447275 Share on other sites More sharing options...
The Little Guy Posted January 23, 2008 Author Share Posted January 23, 2008 actually what I am doing is making sure that the number entered in is a number, and not a string, bool, array, float, or what ever else I missed. if it is not a whole numer... then set the default value ($page) equal to 1. Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447279 Share on other sites More sharing options...
GingerRobot Posted January 23, 2008 Share Posted January 23, 2008 Well, apart from anything else this: if(!is_int($page)){ Will always be true. The is_int() function checks a variable's type. All variables in the $_GET and $_POST array are strings(yes, i suppose you could argue that they can also be arrays, but they are ultimately arrays of strings). The function to use is ctype_digit(), if you want to check a string contains an integer. Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447281 Share on other sites More sharing options...
The Little Guy Posted January 23, 2008 Author Share Posted January 23, 2008 That didn't work... I still get the same error Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447283 Share on other sites More sharing options...
The Little Guy Posted January 23, 2008 Author Share Posted January 23, 2008 OK... The problem was because of an include where it set something... Not sure what was happening, but it works now Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447291 Share on other sites More sharing options...
cooldude832 Posted January 23, 2008 Share Posted January 23, 2008 intval is like strtotime and works wonders on verification of GET/POST that need to be integer types by definition an integer is a whole real number greater than or equal to 0 Quote Link to comment https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447295 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.