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 7638925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:17:31+00:00 2026-05-31T08:17:31+00:00

Ive been trying to crack this for 2 hours, but something is wrong. I

  • 0

Ive been trying to crack this for 2 hours, but something is wrong. I am very much used to doing things without mysqli but read that there is a recommended shift towards it from regular mysql commands. Hence am stuck with following:

<?php   
           $mysqli = new mysqli('localhost', 'admin', 'test123', 'kadmindb'); 
            if ($result = $mysqli->query("SELECT * FROM records WHERE '$queryType' = '$keyword'")) {
                while ($row = $result->fetch_object()) {
                    echo "<h2>Result:</h2><br>";
                    echo "ID: " . $row->id . "<br>";                
                    echo "Name: " . $row->cust_name . "<br>";
                    echo "Invoice No: " . $row->invoice_num . "<br>";
                    echo "Date: " . $row->date_recorded . "<br>";   
                }   

            }

        ?>

This code is shown in the page where the result of the query should be displayed but nothing is displayed. I checked that both keyword and queryType variables are set and they contain the correct values. Any help would be greatly appreciated. All am trying to do is: select statement to retrieve all the details based on invoice_num submitted.

EDIT: from help I received, I was able to get this working:

$query = "SELECT * FROM records WHERE ".$queryType. " LIKE  '%$keyword%' ";
                if ($result = $mysqli->query($query)) {
                    while ($row = $result->fetch_object()) {
                        echo "<h2>Result:</h2><br><hr/> "; 
                        echo "ID: " . $row->id . "<br>";                
                        echo "Name: " . $row->cust_name . "<br>";
                        echo "Invoice No: " . $row->invoice_num . "<br>"; 
                        echo "Date: " . $row->date_recorded . "<br>";   
                        echo "<hr/>";
                    }   

                }
  • 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-05-31T08:17:32+00:00Added an answer on May 31, 2026 at 8:17 am

    Are you sure there’s data to select? This code will only output data if there actually is.

    Make sure that $queryType and $keyword are set and have sane values that will yield a result.

    Use var_dump($queryType) and var_dump($keyword) immediately before the query. Now check your output. Are they both strings? Run this query directly in PHPMyAdmin and check how many rows you get.

    If you can’t do that try echo’ing the number of rows returned along with the query values:

    if ($result = $mysqli->query("SELECT * FROM records WHERE $queryType = '$keyword'"))
    {
        while ($row = $result->fetch_object())
        {
            echo "<h1>Query WHERE '$queryType' = '$keyword' yielded {$result->num_rows} rows!</h1>";
            echo "<h2>Result:</h2><br>";
        ...
    

    Note, you should not have single quotes around the column ($queryType), if you insist you should use backtick quotes (`) but it’s unnecessary really – if you’re that pedantic you should be using prepared statements.

    Also be sure to filter them for any potentially dangerous values that could allow for sql injections. See: mysqli::real_escape_string

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

Sidebar

Related Questions

Ive been trying to get this solved for quite a few hours, but I
Ive been trying to debug this for hours but I was unable to get
I've been trying to crack this nut for a while but I cannot seem
Ive been trying to push a new view when a cell is tapped but
Ive been trying to figure this one out for a while. I need to
Ive been trying to get the parent of this WebBrowser control. Somehow i can't
Ive been trying to teach myself some very basic assembly (output to console, Arithmetic).
Ive been trying to give style to button, The code that I ve used
Ive been trying to acheive the same, this is exactly what i want :-
Ive been trying to write my first Blackberry Adobe Flex application but get the

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.