Jump to content

[SOLVED] What is wrong?


The Little Guy

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447275
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/87454-solved-what-is-wrong/#findComment-447281
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.