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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:12+00:00 2026-05-27T06:41:12+00:00

i have a search function on my website where users can search for products.

  • 0

i have a search function on my website where users can search for products. it works perfectly fine except for the fact that when a user searches for ‘ipod’ it comes up with no result as the name of the product is ‘apple ipod’. how do i code it so that when part of the name of the product is searched, the correct product comes up?

my code is as follows:

    <div id="search" align="right">
<form action="" method="get">
  <span id="sprytextfield1">
  <input name="search" id="search2" type="text" width="250px"/>
  <span class="textfieldRequiredMsg"></span></span>
  <input name="" type="submit" value="Search"/>
</form></div>
<br /><br />
<h2>Your Search Results For "<?php echo $_GET['search'] ?>":</h2><hr />

    <table border="0" cellpadding="2px" width="600px">
        <?
        $search = $_GET['search'];

            $result=mysql_query("select * from products WHERE name = '$search'")
            or die(mysql_error());
if (mysql_num_rows($result) == 0) {
       echo '&nbsp;'.'Could Not Be Found';
    }   
    else {

            while($row=mysql_fetch_array($result)){

        ?>
        <tr>
            <td><?php echo'<img src="getImage.php?id=' . $row['serial'] .'"/>'
?>            </td>
            <td>    <b><a href="pdaproduct.php?product_id=<?=$row['serial']?>"><?=$row['name']?></a></b><br />
                    Price:<big style="color:green">
                        £<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" />
            </td>
        </tr>
        <tr><td colspan="2"><hr size="1" /></td>

        <? 
            }
    }?>
    </table>

thanks for any advice given! 🙂

  • 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-27T06:41:13+00:00Added an answer on May 27, 2026 at 6:41 am

    Ignoring the fact that your code should never be used for production (it’s unsafe), you should use a LIKE in your query.

    mysql_query("select * from products WHERE name LIKE '%$search%'")
    

    Now, optimized against SQL injections and other things you don’t want, this would become:

    mysql_query("select * from products WHERE name LIKE '%".mysql_real_escape_string($search)."%'")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website where users can search for professional wrestling events in the
I have a PHP based website that uses coupon codes. I can restrict search
if i have a search function for my site and i want the user's
How can i have slide downeffect? The effect will be similar with search function
I have a function that uses Pattern#compile and a Matcher to search a list
I have a table that lists users that are registered at my website. The
I have a website that lets users comment on books and articles, and the
I am making a search function on a website to let users search values
I have a website which uses different style sheets from which users can choose
hai I have a magento web site. In this the search function compare with

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.