Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:15:22+00:00 2026-06-12T23:15:22+00:00

I have a simple 7 lined PHP script, as shown below: Code require( connect.php

  • 0

I have a simple 7 lined PHPscript, as shown below:

Code

require( "connect.php" );
$ctg = ($_GET['ctg'])? $_GET['ctg']:'movie';
$offset = ($_GET['off'])? $_GET['off']:30;
$query = "SELECT `msg`, `id`, `nick`, `date` FROM `entries` WHERE `ctg` = ? ORDER BY `id` DESC LIMIT 15 OFFSET ?";
$statemnt = $conn->prepare( $query );
$statemnt->bindParam( 1, $ctg, PDO::PARAM_STR );
$statemnt->bindParam( 2, $offset, PDO::PARAM_INT );
$statemnt->execute();
$results = $statemnt->fetchAll( PDO::FETCH_ASSOC );
echo "$ctg\n$offset\n" . count($results) . "\n";

Problem

The problem I am facing is like this: When I execute the file in console(using php fetch.php), all the echo work great. When I open the page in browser with no $_GET variables, the same output is observed.

The output in browser is the same when I provide it with just the ctg indexed-variable(such as http://localhost/fetch.php?ctg=docu) the output is correct; like this:

docu
30
15

But when I pass the off index-variable(either as fetch.php?off=15 OR fetch.php?ctg=docu&off=15 OR fetch.php?off=15&ctg=docu); The output is always like this:

docu
15
0

Question

The output(and var_dump) both show correct values being passed to both variables, then why is the PDO statement not receiving any results? Why does the count($results) remain 0?

Any help is appreciated.


PS

I also included the following statement:

$statemnt->debugDumpParams();

which dumps this in browser(and console):

SQL: [102] SELECT `msg`, `id`, `nick`, `date` FROM `entries` WHERE `ctg` = ? ORDER BY `id` DESC LIMIT 15 OFFSET ?
Params:  2
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=2
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:15:23+00:00Added an answer on June 12, 2026 at 11:15 pm

    Possibly the $off GET variable is being treated as a string whereas int is expected

    Change:

    $offset = ($_GET['off'])? $_GET['off']:30; 
    

    to

    $offset = ($_GET['off'])?(intval($_GET['off']):30; 
    

    Of course proper validation should exist for all your GETvariables

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to use the php script to generate PDF with a simple
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have wrote a simple php script which reads an IMAP email account and
I have a simple server script that just echos a line: <?php echo Server
I have an extremely simple script with PHP exec , calling mysql command: $dbhost
I have just a PHP script for HTML parsing and it works on simple
The question is pretty simple, the code below shows the items in one category.
Morning all, I have a php script which I have been testing, and seems
I have a simple script that should cause one of three divs to be
yesHave a simple thing here, but not that handy in PHP. Basically I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.