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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:41:48+00:00 2026-05-19T16:41:48+00:00

I wanted to be able to Search in the database at any table whether

  • 0

I wanted to be able to Search in the database at any table whether it is the First Name, Last Name, Middle Name, Etc… the problem is, I always get from query an empty results

This is my attempt

I use the HTML Form for the User to Search With clicking necessary datum.

<table border='0' align='right'>
    <tr>
        <td >
            <select name='SEARCH' id='SEARCH'>
                <option value='ID_NO' selected='selected'>ID Number</option>
                <option value='FNAME'>First Name</option>
                <option value='LNAME' >Last Name</option>
                <option value='MNAME'>Middle Name</option>
                <option value='DATE'>Birthday</option>
                <option value='SEX'>SEX</option>
                <option value='AGE'>Age</option>
                <option value='STATUS'>Status</option>
                <option value='TEL_NO'>Landline Number</option>
                <option value='ADDRESS'>Address</option>
                <option value='OCCUPATION'>Occupation</option>
                <option value='REFERRED_BY '>Referrals</option>
                <option value='itResult'>Result</option>
            </select>
        </td>
        <td rowspan =2><input name='SUBMIT' type='SUBMIT' id='SUBMIT' value='Search!'></td>
    </tr>
    <tr>
        <td><input name='INPUT' type='text' id='INPUT'></td>
    </tr>
    </table>

Then the datum that was entered is pass through here and check to the database

<?php
    print "<center><H2>Search User</H2></center>";
    $ID_CHECK = clean($_POST['chck']);
    $SEARCH = clean($_POST['SEARCH']);
    $INPUT   = clean($_POST['INPUT']);

    $result = mysql_query("SELECT * FROM user_info WHERE '$SEARCH' = '$INPUT'" ) or die('Error, query failed');
    if(!mysql_num_rows($result)) {
        print "<BR>There is no $INPUT in the Database <BR><A HREF ='SearchUser.php'>Go Back</A>";
        exit();
    }
    else {
        $row_array = mysql_fetch_array($result, MYSQL_ASSOC);
?> 

The Problem is, I always get an empty query and that
I think using this is wrong

$result = mysql_query("SELECT * FROM user_info WHERE '$SEARCH' = '$INPUT'" )  or die('Error, query failed');

is there another way? JavaScript perhaps?

My Clean Function does this.. it cleans the value of the data I think

<?php
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
    return mysql_real_escape_string($str);
    }
?>
  • 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-19T16:41:48+00:00Added an answer on May 19, 2026 at 4:41 pm

    Problem is that in your query you are comparing two strings. This should work:

    $result = mysql_query("SELECT * FROM user_info WHERE $SEARCH = '".$INPUT."'")  or die('Error, query failed');
    

    I removed the single quotations from $SEARCH.

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

Sidebar

Related Questions

I wanted to be able to search a name/address/number in my database. I was
I wanted to be able to randomly select rows from a table in a
I would like to be able to use Full text search in Code First
I wanted to be able to Pause/ Resume my NSTimer and found this below
I wanted to be able to set the keyEquivalent of an NSMenuItem based on
I wanted to allow users to be able to add videos but I'm having
What I wanted to achieve is being able to calculate the height and width
I recently wanted to see if I am able to solve an easy sudoku
Something I've wanted to learn for quite a time now, but haven't been able
Recently search engines have been able to page dynamic content on social networking sites.

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.