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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:10:46+00:00 2026-06-15T09:10:46+00:00

Alright, So i am trying to code a little PHP Search Script for My

  • 0

Alright, So i am trying to code a little PHP Search Script for My website so users can simply do a search from a artist name, song name or a city.
My table in my database has ‘city’, ‘artist’ and ‘city’.

Here is my form:

<div id="search">  
<form name="search" method="post" action="../searchDb.php">  
<input type="text" name="find" placeholder="What are we searching for ?"/> in   
<Select NAME="field">  
<Option VALUE="artist">Artist</option>  
<Option VALUE="song">Song</option>  
<Option VALUE="city">City</option>  
</Select>  
<input type="hidden" name="searching" value="yes" />  
<input type="submit" name="search" value="Search" />  
</form>  
</div>  

As you can see, there are three OPTION values (one for each column in my table).
Here is my PHP code:

<?php  
$searching = "searching";  
$find = "find";  
$field = "field";  
 //this is to make sure the user entered content  
if ($searching =="yes")   
{   
   echo "<p><h2>Results</h2></p>";   

   //if user did not enter anything in the search box, give error   
   if ($find == "")   
   {   
      echo "<p>You forgot to enter a search term</p>";   
   }   

   include 'connect.php';   

   // strip whitespace, non case sensitive  
   $find = strtoupper($find);   
   $find = strip_tags($find);   
   $find = trim ($find);   

   //perform search in specified field  
   $data = mysql_query("SELECT * FROM artists_table WHERE upper($field) LIKE'%$find%'");   

   //show results   
   while($result = mysql_fetch_array( $data ))   
   {   
      echo $result['artist'];     
      echo " ";   
      echo $result['song'];    
      echo "<br>";    
      echo $result['city'];    
      echo "<br>";    
      echo "<br>";   
   }   

   //counts results. ifnone. error    
  $anymatches=mysql_num_rows($data);    
   if ($anymatches == 0)    
   {    
      echo "Sorry, but we can not find an entry to match your query<br><br>";    
   }    

   //show user what he searched.   
   echo "<b>Searched For:</b> " .$find;     
 }     
 ?>     

My connect.php (that is included) works perfectly (i have that same file working on another page, no problems..So its safe to say thats not the problem).

When i do a test and run a search, it loads up my searchDb.php but NOTHING is displayed. Simply a white page…

Any help would be greatly appreciated. I am lost as to why or what is not working…
Thanks Guys !

  • 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-15T09:10:47+00:00Added an answer on June 15, 2026 at 9:10 am

    If this is your code, then you are hardcoding $searching = "searching", but in your if you are checking if $searching =="yes", so none of the code will show.

    <?php  
    $searching = "searching";  
    ...
    ...  
    //this is to make sure the user entered content  
    if ($searching =="yes")   
    {   
    ...
    }
    

    Edit-

    My guess is that you wanted to do something like-

    $searching = mysql_real_escape_string($_POST['searching']); // sanitized just to be consistant.  
    $find = mysql_real_escape_string($_POST['find']);  
    $field = mysql_real_escape_string($_POST['field']);
    

    Note- you should not be writing new code with mysql_* functions. You should learn either mysqli_ or PDO – http://php.net/manual/en/mysqlinfo.api.choosing.php

    Here are 2 ways to avoid getting the "Notice: Undefined variable"

    Check if submit button was pushed

    if (isset($_POST['search'])) {
    $searching = mysql_real_escape_string($_POST['searching']); // sanitized just to be consistant.  
    $find = mysql_real_escape_string($_POST['find']);  
    $field = mysql_real_escape_string($_POST['field']);
    }
    

    Or check if each field is set, and set it to the value, and if not set to no/empty

    if (isset($_POST['search'])) {  // checks to see if the form submit button was pushed
    $searching = isset($_POST['search']) ? mysql_real_escape_string($_POST['searching']) : 'no'; // sanitized just to be consistant.  
    $find = isset($_POST['find']) ? mysql_real_escape_string($_POST['find']) : '';  
    $field = isset($_POST['field']) ? mysql_real_escape_string($_POST['field']) : '';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, here I am again trying to write code from scratch and I can't
Alright, so here's my problem. I'm trying to write a script in PHP that
Alright so I'm trying to embed an swf file with this code: <object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000
Alright, so I have this collision detection code, and I'm trying to push the
Alright well I am trying to create a dictionary from a text file so
Alright I'm pretty new to programming and stuff and I'm now trying to code
Alright, I'm trying to write some code that removes words that contain an apostrophe
Alright, I'm trying to set a program I have to receive data from a
Alright... I'm trying to write some javascript code that will apply to an html
Alright, if you look at the code below, I am trying to make it

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.