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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:29:26+00:00 2026-06-17T06:29:26+00:00

My php mysql query isn’t working or at least thats what I assume. If

  • 0

My php mysql query isn’t working or at least thats what I assume. If you guys could maybe notice something I am not seeing it would be greatly appreciated. Thanks!

Here are the errors I am receiving:

Notice: Trying to get property of non-object in D:\
Fatal error: Call to a member function free() on a non-object in D:\

I have 9 columns with varchar:

Part Number,Alternate Partnumber,Qty,
Description,Part Condition Code,Price,
Location,Barcode,Consignment

I have created a search bar and I want customers to be able to enter in a part number and it finds that part number and all of the info on its row.

I am using Php and Mysql Web Development by Luke Welling and Laura Thomson
So I am using part of they’re code from a chapter.

Here is the code:

<?php
    //create short variable names
    $searchtype = "Part Number";
    $searchterm = $_POST['searchterm'];

    //echo "$searchtype";
    //echo "$searchterm";

    if(!$searchtype || !$searchterm)
    {
        echo 'You must enter a part number please try again';
        exit;
    }

    if(!get_magic_quotes_gpc())
    {
        $searchtype = addslashes($searchtype);
        $searchterm = addslashes($searchterm);
    }

    @ $db = new mysqli('localhost', 'username', 'password', 'partstest');

    if(mysqli_connect_errno())
    {
        echo 'Error: Could not connect to database. Please try again later.';
        exit;
    }

    //$query = "SELECT $searchterm * FROM inventory WHERE Part Number";
    $query = "select * from inventory where " .$searchtype. " like '%".$searchterm."%'";


    $result = $db->query($query);
    //$result = mysqli_query($db, $query);

    $num_results = $result->num_rows;
    //$num_results = mysqli_num_rows($result);

    echo "<p>Number of books found: ".$num_results."</p>";

    for($i = 0; $i < $num_results; $i++)
    {
        $row = $result->fetch_assoc();
        //$row = mysqli_fetch_assoc($result);
        echo "<p><strong>".($i+1).". Part Number: ";
        echo htmlspecialchars(stripslashes($row['Part Number']));
        echo "</strong><br /> Alternate Part Number: ";
        echo stripslashes($row['Alternate Part Number']);
        echo "<br />Qty: ";
        echo stripslashes($row['Qty']);
        echo "<br />Description: ";
        echo stripslashes($row['Description']);
        echo "<br />Part Condition: ";
        echo stripslashes($row['Part Condition']);
        echo "<br />Price: ";
        echo stripslashes($row['Price']);
        echo "<br />Location: ";
        echo stripslashes($row['Location']);
        echo "<br />Barcode: ";
        echo stripslashes($row['Barcode']);
        echo "<br />Consignment: ";
        echo stripslashes($row['Consignment']);
        echo "</p>";

    }

    $result->free();
    //mysqli_free_result($result);
    $db->close();

    ?>
  • 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-17T06:29:27+00:00Added an answer on June 17, 2026 at 6:29 am

    Can you please post the output of the following code:

    var_dump(get_object_vars($result));
    

    Seems your $db is empty due to misplaced @

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

Sidebar

Related Questions

Possible Duplicate: mysql case sensitive query 'm working on an PHP script that checks
I'm doing an insert MySQL query in PHP with something like this: $inserto= sprintf(INSERT
I am using a PHP mySQL query. Struggling with a Joins. mysql_query(SELECT * FROM
I have a PHP/MySQL query that returns to an HTML table, and I'm stuck
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
Let's say that I have an error in a php/mysql query : $query =
I have the following mysql query which I am running with php like so.
I have a php script that runs a mysql query, then loops the result,
I wrote a PHP script that retrieves values from a MySQL Query. I used
i am trying to pass date to mysql query using php, but i am

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.