mysql - PHP pagination SQL Syntax error when page= -1 -
when check url page pagination, pagination worked , show page result in page , page=+1:
mydomain/search.php?page=1 mydomain/search.php?page=2
but when check url:
mydomain/search.php?page=-1 mydomain/search.php?page=-2
i see error:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near '-20, 10' @ line 1
i print result using pagination code:
// if number of results bigger maximum number // of search results set in config start pagination if ( $results > $conf['search_results'] ) { // calculate first number of page show // makes list of pages numbers smaller if ((($page*$conf['search_results'])-($conf['search_results']*5)) >= 0) $first=($page*$conf['search_results'])-($conf['search_results']*5); else $first=0; // calculate last element of pagination list if ((($page*$conf['search_results'])+($conf['search_results']*6)) <= $results) $last =($page*$conf['search_results'])+($conf['search_results']*6); else $last = $results; @ $i=$first/$conf['search_results']; // previous link if ($page > 0) { $pagenum = $page - 1; echo ' <a style="float:left;" href="' . url . '/search.php?page=' . $pagenum . '&' . $session->fetch('listingsearchvariablespage') . '">pre</a> | '; } // middle pagination ( $step = $first; $step < $last; $step=$step+$conf['search_results'] ) { if ( $i == $page ) { $pagenum = $i+1; echo ' <span class="warning">' . $pagenum . '</span> | '; $i++; } else { $pagenum = $i+1; echo ' <a href="' . url . '/search.php?page=' . $i . '&' . $session->fetch('listingsearchvariablespage') . '">' . $pagenum . '</a> | '; $i++; } } // next link if ($page - (($results / $conf['search_results']) - 1) < 0) { $pagenum = $page+1; echo ' <a style="float:right;" href="' . url . '/search.php?page=' . $pagenum . '&' . $session->fetch('listingsearchvariablespage') . '">next</a>'; } }
now, how can fix error negative number , prevent attack?
i'd recommend simple like:
if($page < 1) $page = 1;
Comments
Post a Comment