html - How to retrieve data from MYSQL database using checkboxes in PHP and how to set an if statement to give you an specific result by comparing? -


before start on things , inform have tried find in web, youtube , books , seems don't clue trying do.

the main feature of page following example: mysql database in xampp , html page php on it. php code conects db , have created 3 checkboxes -

  • 1 - mouse
  • 2 - dog
  • 3 - tiger

( things checkboxes options. input button (to retrieve info)

if select checkbox 1 php code should call table animals , give result mouse

but want if user select mouse , dog, retrieve fastest animal in case checkbox 2: or if user select 3 of them gives result number 3 (tiger.)

i being watching tutorials , on retrieve got html part can connect db, questions

how set first checkboxes? how call database each of checkboxes? comparison statement need use in order give me desired logic?

html>          <head>               <title>fastest animal selection</title>         </head>          <body>            <div class="container box">            <h3 align="center">fastest animal selection</h3><br />            <h4>please select animal.</h4><br />              <form method="post">             <p><input type="checkbox" name="animal[]" value="mouse" /> mouse</p>             <p><input type="checkbox" name="animal[]" value="dog" /> dog</p>             <p><input type="checkbox" name="animal[]" value="tiger" /> tiger</p>             <p><input type="submit" name="submit" class="btn btn-info" value="get fastest animal" /></p>            </form>            <?php  		 if(isset($_post["submit"]))            {             $for_query = '';             if(!empty($_post["animal"]))             {              foreach($_post["animal"] $animal)              {               echo '<p>'.$animal.'</p>';  			 }  			 }  			 else  				{   			echo "<label class='text-danger'>* please select @ least 1 animal.</label>";  			}  			}  			?>  			</div>          </body>     </html>

$_post["animal"] empty if click on 1 checkbox or more of them. because $_post["animal"] doesn't exist in form. animal[] exist. name have checkbox needs same $_post["animal"].

so if change this: name="animal[]" this: name="animal[]" believe work then.

so short version name choose checkbox need same when want call $_post[""].

after you'll have make sql query gets result of need. try if don't know how make sql query https://www.w3schools.com/sql/sql_syntax.asp


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -