mardi 29 décembre 2015

Sending and receiving checkbox data to and from SQL w/PHP

I am trying to figure out the SQL code that I would need to pass an array of checkbox data to sql, and then pull the same array back out of sql for a form afterwards. I received some help from a friend on how to save the data into an array, but do not know the best practice to pull the array from SQL in the form of checkbox data.

This is what I have so far for my form :

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-default active">Apples
        <input type="checkbox" name="fruit[]" value="Apples" <?= in_array('Apples', $invoice['basket']['fruit']) ? '' : '' ?> autocomplete="off">
    </label>
    <label class="btn btn-default active">Bananas
        <input type="checkbox" name="fruit[]" value="Bananas" <?= in_array('Bananas', $invoice['basket']['fruit']) ? '' : '' ?> autocomplete="off">
    </label>
    <label class="btn btn-default active">Oranges
        <input type="checkbox" name="fruit[]" value="Oranges" <?= in_array('Oranges', $invoice['basket']['fruit']) ? '' : '' ?> autocomplete="off">
    </label>

This is how I can pull NON-ARRAY data, looking for correct code for the array :

$fruit = mysqli_real_escape_string( $this->_con, isset( $basket['fruit']) ? 1 : 0);




Aucun commentaire:

Enregistrer un commentaire