Jump to content

PHP, mySql query &checkboxes.


smokey20

Recommended Posts

Hi

 

I am trying to display some rows from a database table based on choices submitted by the user. Here is my form code

 

        <form action="choice.php" method="POST" >

      <input type="checkbox" name="variable[]" value="Apple">Apple

      <input type="checkbox" name="variable[]"   

      value="Banana">Banana

      <input type="checkbox" name="variable[]"

      value="Orange">Orange

      <input type="checkbox" name="variable[]" value="Melon">Melon

      <input type="checkbox" name="variable[]"   

      value="Blackberry">Blackberry

 

From what I understand I am placing the values of these into an array called variable.

Two of my columns are called receipe name and ingredients(each field under ingredients can store a number of fruits).  What I would like to do is, if a number of checkboxes are selected then the receipe name/s is displayed.

 

Here is my php code.

 

    <?php

    // Make a MySQL Connection

    mysql_connect("localhost", "*****", "*****") or die(mysql_error());

    mysql_select_db("****") or die(mysql_error());

 

    $variable=$_POST['variable'];

    foreach ($variable as $variablename)

    {

    echo "$variablename is checked";

    }

 

    $query = "SELECT receipename FROM fruit WHERE $variable like ingredients";

 

    $row = mysql_fetch_assoc($result);

    foreach ($_POST['variabble'] as $ingredients)

    echo $row[$ingredients] . '<br/>';

    ?>

 

I am very new to php and just wish to display the data, I do not need to perform any actions on it.  I have tried many select statements  :-\ but I cannot get any results to display.  My db connection is fine and it does print out what variables are checked.

 

I did post this on a general forum also, but as this is a dedicated php site I thought this may be a better option.

 

Many thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/200002-php-mysql-query-checkboxes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.