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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:20:30+00:00 2026-05-28T01:20:30+00:00

In index.php I have a form and in the form a text field: <form

  • 0

In index.php I have a form and in the form a text field:

<form name="UserSearch" action="petSearch.php" method="GET">
     <input type="text" name="petWish" value="" />
</form>

where the user enters what pets they want into the text box (seperated by commas) e.g dog, cat, fish, snake

In petSearch.php, I use the following function to create a legal SQL string that can be used in a SQL statement:

<?php    
    $userPetWish = mysqli_real_escape_string($link, $_GET["petWish"]);
?>

I then create the SQL statement and query the MySQL database:

<?php
    $query="SELECT petType, name, age FROM pets WHERE petType LIKE '%".$userPetWish."%'";
    $result = mysqli_query($link, $query);

      if($result)
      {
          while($row = mysqli_fetch_array($result))
          {
             echo "From the pets you entered we have" . $row[petType] . "," . $row[name] . "," . $row[age];
          }
      }
      else
      {
         echo "Sorry we do not have any of your chosen pets in store";
      }
?>

So my question is:

1) In order to search for each individual pet against the database, is it possible to ‘split’ the pets which the user entered by commas and then query the Pet table in the database using the “LIKE” function? If so, can you tell me how to structure this?

2) If after doing the search against the database there is a dog, cat and fish in store, but no snake. How do i get it to display this, to show the petType, name and age they have of the three pets, but not the snake? (I’m not sure if the way I structured this in the while loop is correct)

  • 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-28T01:20:30+00:00Added an answer on May 28, 2026 at 1:20 am

    You can use

    explode( ',', $userPetWish )
    

    to split the words up.

    Also a note I would use

    echo 'From the pets you entered we have' . $row['petType'] . ',' . $row['name'] .
        ',' . $row['age'];
    

    Instead of no quotes within the $row;

    Also your better of stripping the slashes strip_slashes ( $userPetWish ) if your using a LIKE otherwise your going to get slashes in the query and might break it ( may be wrong, just what ive experienced )

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

Sidebar

Related Questions

I do have a search form. <form method=get id=searchform action=<?php bloginfo('siteurl');?>> <div class=search_bx1><input type=text
In index.php I have a form: <form name=UserLocation action=propForSale.php method=GET> Once the user types
I have a search form on my site <form class=clearfix action=search.php method=get> <h1>Search the
I have a post html form, and the action is index.php, which is the
I have a pege (index.php) with some text and a form with a single
I have a form field with items <label for='usrad_resi'> Residential Address </label><input id='usrad_resi' name='usrad_resi'
In index.php, I have created a form and in the action attribute of the
In a php-script i have a form, method is post, action-attribute is empty, which
Here's my problem: I have a form in index.html, it will have a text
I have the following code in my main index.php: <div class=form> <?php $oForm =

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.