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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:16:36+00:00 2026-05-20T10:16:36+00:00

I have a form like this: <form method=post action=> <?php $h = mysql_query(select distinct

  • 0

I have a form like this:

<form method="post" action="">
<?php
$h = mysql_query("select distinct sous_sous_categorie, sous_sous_categorie_url  
                  from articles where sous_categorie_url='".$_GET["s_cat"]."' ");
while($hRow=mysql_fetch_assoc($h)){  
?>
    <span class="submit">
    <input type="checkbox" name="<?php echo $hRow["sous_sous_categorie_url"]; ?>" 
     value="<?php echo $hRow["sous_sous_categorie_url"]; ?>" />&nbsp;&nbsp;
    <a href="?categorie=<?php echo $_GET["categorie"];  ?>&s_cat=<?php echo $_GET["s_cat"]; ?>&s_s_cat=<?php echo $hRow["sous_sous_categorie_url"];  ?>"><?php echo $hRow["sous_sous_categorie"];  ?></a>
    </span>
<?php } ?>
<input type="submit" name="submit_sous_sous_categorie_search" 
 value="search" class="submit" />
</form>

as you can see the form is in a loop, the form consists of checkboxes that user will check and accoding to this a search query will be made, the thing is that checkboxes have the name attribute but this attribute is variable (because it is fetch from the db) so my question is how can I make this:

if(checkboxes are empty){
    echo "you must at least select one checkbox"
}

This is just an example but I dont see how to do a simple thing such as

if(!$_POST["checkbox"]}{
    echo "you must at least select one checkbox";
}

Again, because the name of the checkboxes are variable.

  • 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-20T10:16:36+00:00Added an answer on May 20, 2026 at 10:16 am

    You can make your checkboxes into an array by changing the name to:

    name="checkboxes[<?php echo $hRow["sous_sous_categorie_url"]; ?>]"
    

    Then you can use code like this to make sure at least one is checked:

    $passed = false;
    if( isset( $_POST['checkboxes'] ) && is_array( $_POST['checkboxes'] ) )
    {
        foreach( $_POST['checkboxes'] as $k => $v )
        {
            if( $v )
            {
                $passed = true;
                break;
            }
        }
    }
    
    if( ! $passed )
    {
        echo "You must select at least one checkbox";
        exit();
    }
    

    Also, you should be careful with your query there, you need to escape that to prevent SQL injection.

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

Sidebar

Related Questions

I have a form that looks like this. <form action=index.php method=post> <select name=dropdownOption> <option
I have form like this: <form method=POST action=<?php echo base_url() ?>admin/admin_search> <fieldset> <label for=nalozi>Nalozi</label><input
I have a form like this: <form action=form_send.php method=post> <table> <tr> <td><label for=address>address</label></td> <td><input
I have a form like this: <form id=surveyForm method=post action=submit.php> <input type=text id=good value=0
I have a simple form like this : <form method=post name=change_pass id=change_pass action=change_pass2.php> <input
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have a form like this: <form id=loginCompact action=https://externalsite... name=sportsbook method=post onsubmit=createCookie('BRLOG', document.sportsbook.username.value, 1)>
So I got this form: <form action=welcome.php method=post> <input type=hidden name=secret value=<?php echo getMyValue()
I have set up the following form: <form name=pric method=post action=up.php> <div id=prices_col>Season A<br>
I have an input form for a sample php. <form action=insert.php method=post> <table> <tr>

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.