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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:48:03+00:00 2026-06-17T21:48:03+00:00

I am having my first attempts to a search engine: I have a database

  • 0

I am having my first attempts to a search engine:
I have a database called “global” and a table called “mpl” which contains 11 columns (Named: Customer, Part No, Descripton, Country Of Origin, and several other) with multiple rows for parts.
What i aim to do with the code below – is to get the Description and Country Of Origin displayed for the Part No the user has entered to the search field.

Form:

<form action="search.php" method="post"> 
<input type="text" name="find" /><br /> 
<input type="submit" value="Search" /> </form>

And the PHP:

$host = "localhost"; 
$dbuser = "root"; 
$dbpass = " "; 
$db = "global"; 

$con = mysql_connect($host, $dbuser, $dbpass);
    if(!$con){ die(mysql_error());
    } 
$select = mysql_select_db($db, $con);
    if(!$select){ die(mysql_error()); 
    } 
$item = $_REQUEST['find'];  
$data = mysql_query("SELECT * FROM mpl WHERE 'Part No' ='".$item."'"); 
while($row = mysql_fetch_array($data)){ 
        echo $row['Description']. "<br>";
        echo $row['Country Of Origin']. "<br><p>"; 
 } 

 ?>

Can someone tell me what am i doing wrong? Once i enter anything to my form ‘find’ – i get no results. If i run the search using LIKE instead of “=” with no value – it displays a bunch of Descriptions and Country of origin – this means i have connected to my DB correctly. This is driving me nuts..I feel i have messed up the mysql_query() part somehow – but i can’t figure out which part.

  • 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-17T21:48:05+00:00Added an answer on June 17, 2026 at 9:48 pm

    A lot of people here have already pointed out possible and actual errors in your code, but here’s the combined solution. Firstly I converted your code to mysqli which is the correct way of connecting to a mySQL database. The way you were connecting is out of date, and not recommended. Secondly I added some code to stop sql injection. Thirdly, I changed 'Part No' to `Part No“(ignore the second back tick) in your query.

    <?php
    
    $mysqli = new mysqli('localhost', 'root', DB_PASSWORD, 'global');
    
    /* check connection */
    if ($mysqli->connect_error)
      die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
    
    /* escape string from sql injection */
    $item = $mysqli->real_escape_string($_POST['find']);
    
    /* query database */
    $result = $mysqli->query("SELECT * FROM `mpl` WHERE `Part No` = '".$item."'");
    while ($col = $result->fetch_array(MYSQLI_ASSOC))
      echo '<p>' . $col['Description'] . '<br />' . $col['Country Of Origin'] . '</p>';
    $result->close();
    
    /* don't forget to close the connection */
    $mysqli->close();
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I want is to have a table having a first column with every
In my html table I have two row, first row having no css but
I'm having some problems upgrading Python on my Mac. For my first attempt, I
I'm having my first play around with Ember.js, and am falling at the first
First time cake user and I'm having real apache problems. For some reason the
First of all I am having trouble with the concept of a mathematical Vector
The problem I'm having is that the first URL works and the second one
The problem I'm having is that the first URL works and the second one
So this is my first time using cookies and i'm having some trouble setting
Am working with my first storyboard application and am having a problem. When I

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.