Jump to content

whats wrong with this?


rex9990

Recommended Posts

Here is code i have and im a bit confused about

 

$charset='UTF-8';
$page1  =  htmlentities ($_GET['page'], ENT_NOQUOTES, $charset);
if(!isset($page1)){ 
    $page = 1; 
} else { 
    $page = '$page1'; 
} 
$max_results = 10; 
$from = (($page * $max_results) - $max_results);

 

it gives me the error

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 '-10, 10' at line 1

 

but if i change "if(!isset($page1))" to "if(!isset($test))" it excutes the page right but with some smaller errors :|

Can anyone see whats going wrong?

Thanks

Steve

Link to comment
https://forums.phpfreaks.com/topic/94492-whats-wrong-with-this/
Share on other sites

Well, I'm not sure what you are trying to accomplish with the htmlentities() command (you should be validating that the value is a whole number). But, your problem is this line:

$page = '$page1';

 

It is setting $page to the string value of "$page1". In fact there is no reason for that line at all:

 

$charset='UTF-8';
$page  =  htmlentities ($_GET['page'], ENT_NOQUOTES, $charset);

if(!isset($page)){ 
    $page = 1; 
} 

$max_results = 10; 
$from = (($page * $max_results) - $max_results);

 

Although I still think you should be doing a different validation other than htmlentities().

 

Link to comment
https://forums.phpfreaks.com/topic/94492-whats-wrong-with-this/#findComment-483903
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.