Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.