Creating a search form in PHP duplicate

0 votes

I am working on a function where the specifications are to use a search form to search through a packaging database. I wanted to create a search form where users can search using different searches.

Creation of database:

 <body>
  <?php
     $con = mysql_connect("localhost", "root", "");
      if (!$con)
     {
      die('Could not connect: ' . mysql_error());
     }
      if (mysql_query("CREATE DATABASE db_test", $con))
     {
  echo "Database created";
     }
      else
    {
  echo "Error creating database: " . mysql_error();
    }


  mysql_select_db("db_test", $con);
  $sql = "CREATE TABLE Liam
   ( 
  Code varchar (30),
  Description varchar (30),
  Category varchar (30),
  CutSize varchar (30),
   )";

 mysql_query($sql, $con);
     mysql_close($con);
 ?> 
   </body>

HTML search form page:

<body>

      <form action="form.php" method="post">
        Search: <input type="text" name="term" /><br />
      <input type="submit" name="submit" value="Submit" />
      </form>

</body>

The PHP code I am using to attempt to gather info from the database (I have rewritten this a few times, this code also displays the "table.liam doesn't exist")

  <body>
   <?php
 $con = mysql_connect ("localhost", "root", "");
 mysql_select_db ("db_test", $con);

  if (!$con)
    { 
    die ("Could not connect: " . mysql_error());
    } 
    $sql = mysql_query("SELECT * FROM Liam WHERE Description LIKE '%term%'") or die
        (mysql_error());

       while ($row = mysql_fetch_array($sql)){
    echo 'Primary key: ' .$row['PRIMARYKEY'];
    echo '<br /> Code: ' .$row['Code'];
    echo '<br /> Description: '.$row['Description'];
    echo '<br /> Category: '.$row['Category'];
    echo '<br /> Cut Size: '.$row['CutSize']; 
  }
 
  mysql_close($con)
   ?>
     </body>

Can someone give me some idea or a solution to do this?

Jun 9, 2022 in PHP by Kichu
• 19,040 points
415 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
0 answers

Creating a very simple 1 username/password login in php

I am working on a function that ...READ MORE

May 29, 2022 in PHP by Kichu
• 19,040 points
1,190 views
0 votes
0 answers

Creating a config file in PHP

I am working on creating config file ...READ MORE

Jun 24, 2022 in PHP by narikkadan
• 63,600 points
390 views
0 votes
2 answers

How can we create a session in PHP?

Hello, niroj. Here is my idea session_start(); $_SESSION['USERNAME'] ...READ MORE

answered Dec 7, 2020 in PHP by Famous
• 140 points
1,180 views
0 votes
1 answer

How to implement a callback in PHP?

Hello, Implementation of a callback is done like ...READ MORE

answered Apr 15, 2020 in PHP by Niroj
• 82,840 points
985 views
0 votes
1 answer

How can I connect to a Tor hidden service using CURL in PHP?

Hello @kartik, I use Privoxy and cURL to scrape Tor ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,840 points
5,319 views
0 votes
1 answer

How do I convert a PDF document to a preview image in PHP?

Hello @kartik, You need ImageMagick and GhostScript <?php $im = new imagick('file.pdf[0]'); $im->setImageFormat('jpg'); header('Content-Type: image/jpeg'); echo ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,840 points
4,786 views
0 votes
2 answers

How to send data to my database from html and css Contact Us Form?

Hello @Sign, It is simple to create contact ...READ MORE

answered Aug 4, 2020 in Database by Niroj
• 82,840 points
36,006 views
0 votes
0 answers

Establishing PHP connection with localhost server?

I am having trouble connecting my PHP ...READ MORE

Jun 3, 2022 in PHP by Kichu
• 19,040 points
482 views
0 votes
0 answers

How to retrieve data from multiple tables using a PHP form?

I want to retrieve data from multiple ...READ MORE

Jun 25, 2022 in PHP by narikkadan
• 63,600 points
1,964 views
0 votes
0 answers

How to export PHP/MYSQL data to PDF?

When I develop a student information form ...READ MORE

Jul 31, 2022 in PHP by Kithuzzz
• 38,000 points
568 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP