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

  • Home
  • SEARCH
  • 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 125431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:09:28+00:00 2026-05-11T05:09:28+00:00

I have the following simple mysqli php application, which should work fine. $pk is

  • 0

I have the following simple mysqli php application, which should work fine. $pk is accepted perfectly and is a valid ARTICLE_NO, and the query works perfectly when executed directly by mysql. I have put output statements after every event and all except tetsing while executes. The while loop is never entered, and I am unsure why.

edit: I have narrowed the problem down to the fact that 0 rows are returned, but I have no idea why as the same query in phpmyadmin gives the right result.

edit2: if I get rid of the while loop and just have

    if (!$getRecords->fetch()) {     printf('<p>ErrorNumber: %d\n', $getRecords->errno); } 

It shows that the errno is 0. So no records are fetched, and there is no error, yet it is a valid query.

<?php ini_set('display_errors', '1'); error_reporting(E_ALL); $pk = $_GET['pk']; $con = mysqli_connect('localhost', '', '', ''); if (!$con) {     echo 'Can't connect to MySQL Server. Errorcode: %s\n'. mysqli_connect_error();     exit; } $con->set_charset('utf8'); echo 'test outside loop'; if(1 < 2) {     echo 'test inside loop';     $query1 = 'SELECT ARTICLE_NO FROM AUCTIONS WHERE ARTICLE_NO = ?';     if ($getRecords = $con->prepare($query1)) { echo 'inside second loop';         $getRecords->bind_param('i', $pk); echo 'test after bind param';         $getRecords->execute(); echo 'test after bind execute';         $getRecords->bind_result($ARTICLE_NO); echo 'test after bind result';         while ($getRecords->fetch()) {             echo 'test inside while';             echo '<h1>'.$ARTICLE_NO.'</h1>';         }     } } 

edit:

I tried with this code:

<?php $mysqli = new mysqli('localhost', '', '', ''); $pk = $_GET['pk']; if (mysqli_connect_errno()) {     printf('Connect failed: %s\n', mysqli_connect_error());     exit(); } /* prepare statement */ if ($stmt = $mysqli->prepare('SELECT ARTICLE_NAME, WATCH FROM AUCTIONS WHERE ARTICLE_NO = ? LIMIT 5')) {     $stmt->bind_param('i', $pk);     $stmt->execute();     /* bind variables to prepared statement */     $stmt->bind_result($col1, $col2);     /* fetch values */     while ($stmt->fetch()) {         printf('%s %s\n', $col1, $col2);     }     /* close statement */     $stmt->close(); } /* close connection */ $mysqli->close(); ?> 

This works without $pk, if I take away the parameters it works fine. It is not a problem with getting pk via GET, because if I assign $pk = 1; instead it still fails. 1 is a valid ARTICLE_NO, and SELECT ARTICLE_NAME, WATCH FROM AUCTIONS WHERE ARTICLE_NO = 1 LIMIT 5 works fine in phmyadmin.

edit: the problem was that mysqli could not handle bigint, I am now using k as a string and it works fine.

  • 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. 2026-05-11T05:09:29+00:00Added an answer on May 11, 2026 at 5:09 am

    Check the value of:

    $getRecords->num_rows 

    which should help reveal whether the earlier SELECT is actually returning any data

    You may need to also add:

    $getRecords->store_result() 

    first to ensure that you’ve the whole query has completed before asking for the number of rows in the result set.

    Also – make sure you cast $pk to an integer! It’s possible that the value being passed in is getting mangled.

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's been a while since I've used Prototype, but on… May 12, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer Hi, I was wondering why MYSQL uses a single equals… May 12, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer The Repeater is designed for web form and works with… May 12, 2026 at 1:16 am

Related Questions

How would you implement a system with the following objectives: Manage authentication, authorization for
I am part of a team creating a web application using PHP and MySQL.
I have a mostly desktop programming background. In my spare time I dabble in
I'm trying to find a simple MySQL statement for the following two problems: I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.