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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:41:55+00:00 2026-05-28T05:41:55+00:00

I have one table: CREATE TABLE IF NOT EXISTS `test` ( `firstname` varchar(100) NOT

  • 0

I have one table:

CREATE TABLE IF NOT EXISTS `test` (
  `firstname` varchar(100) NOT NULL,
  `lastname` varchar(100) NOT NULL,
  `nickname` varchar(100) NOT NULL
)

I have this html code:

<form action="" method="post">
<input name="firstname" type="text" />
<input name="lastname" type="text" />
<input name="nickname" type="text" />
<input type="submit" value="search" />
</form>

I need that when I fill firstname text box my query condition is:

firstname=$_REQUEST['firstname']

And when this text box is not filled in this condition should not be used.
I want it that when I fill two text boxes or three text boxes, the correspond condition is checked but I need one query to do this.

  • 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-28T05:41:55+00:00Added an answer on May 28, 2026 at 5:41 am

    Taking the start from Ampere …

    $firstname=mysql_real_escape_string(trim($_POST['firstname']));
    $lastname=mysql_real_escape_string(trim($_POST['lastname']));
    $nickname=mysql_real_escape_string(trim($_POST['nickname']));
    

    … and then build the query depending on which input fields are not empty:

    $query="SELECT * FROM `test` WHERE 1";
    if ($firstname) $query .= " AND `firstname`='$firstname'";
    if ($lastname) $query .= " AND `lastname`='$lastname'";
    if ($nickname) $query .= " AND `nickname`='$nickname'";
    

    If you leave all fields blank, your query will select all rows. If you enter some information, every given field must match the appropriate column.

    PS: Maybe you want also to return “Edward” as well, when someone enters “Ed” into the the firstname field. You can use LIKE '%Ed%' instead of ='Ed' in your WHERE statements: firstname LIKE '%{$firstname}%'

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

Sidebar

Related Questions

I have this test table with one row entry and 2 indexes, the first
I have the following table: CREATE TABLE IF NOT EXISTS `notes` ( `id` int(10)
I have a following table: CREATE TABLE IF NOT EXISTS `Tree` ( `id` int(10)
I have two tables: CREATE TABLE IF NOT EXISTS `comments` ( `id` int(11) NOT
I have 2 tables as the following - CREATE TABLE IF NOT EXISTS `nl_members`
I have a table created using Python + Sqlite3 c.execute('CREATE TABLE IF NOT EXISTS
I have created one table using the below command: create table Table1( Id int
I have to create one table using XSLT and CSS. The table should look
Ok, I have one JavaScript that creates rows in a table like this: function
Lets say I have one table called REVIEWS This table has Reviews that customers

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.