I am new to both html and php and I am trying to create a form that you have one text box with buttons that allow you to search for the item in the text box in the last 24, 48,72 hours.
One the html side of things my form looks like this:

     <form action="test.php" method="GET">
        <input type="text" name="query" />
        <input type="submit" value="Search" />
        <input type="submit" name="oneday" value="Last 24 hours">
        <input type="submit" name="twoday" value ="Last 48 hours"/>
        <input type="submit" name="threeday" value="Last 72 hours"/>
    </form>

When it gets the php it seems to always search for query and not the other values.

php code is :

<?php
    $query = $_GET['query']; 
    $queryo = $_GET['oneday'];
    $querytwo = $_GET['twoday'];
    $queryth = $_GET['threeday'];

    $min_length = 3;

    if($query) >= $min_length){
    mysql command
    else{
    if($queryo) >= $min_length){
    mysql command
    else{
    if($querytwo) >= $min_length){
    mysql command
    }

I am very new to coding and have never done any web stuff at all so any help would be great. I am guessing I am missing something in front of my face but need a point or some help.
Thank you in advance.

I'm not that great on PHP yet, but just following the logic of your code... When the form is submitted, these input elements are going to be available on the target page (test.php). On your target page, you are assigning a variable $min_length = 3.

Ok, then your first conditional statement is checking to see if $query is greater than or equal to 3. Not sure why you are doing that, but in any case, no matter how many times you submit this form, that evaluation is always resulting in the same way.. as TRUE and that is why you are seeing that PHP seems to always search for query and not the other values.

When I remove the $min_length = 3 it still searches for dates from the last 30 days instead of the last 1 day. I don't want anyone searching for anything less then 3 as it would return to many useless results from the db.
I did check the mysql command using mysql and it returned the proper results.

@iamthwee I didn't go with a radio button as it didn't look nice on the page and I didn't want to change the format.

I don't want anyone searching for anything less then 3 as it would return to many useless results from the db.

Maybe its my lack of expert PHP knowledge or there's some of your code missing but it appears to me that you are comparing text values with the number 3. Am I missing something here?

What do think these variables are storing with regard to values?

 $query
 $queryo
 $querytwo
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.