mardi 11 juin 2019

MySQL table containing text inputs and checkbox values

I know this isn't the right place for this sort of requests but I don't know where to search for help !

I'm completely new to PHP and MySQL. I'm trying to make a simple form for billing information (text inputs) and chosen articles (checkboxes). Here is what the form looks like : what the form looks like

This is the HTML :

<form method="post" action="/commande/informations/commande.php">
        <div id="commande">
            <legend>Choisissez les articles souhaités :</legend>

            <div>
                <input type="checkbox" id="polo" name="article" value="polo" />

                <label for="polo">Polo<span>20 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="tshirtw" name="article" value="tshirtw" />

                <label for="tshirtw">T-Shirt blanc<span>10 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="tshirtb" name="article" value="tshirtb" />

                <label for="tshirtb">T-Shirt bleu<span>10 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="veste" name="article" value="veste" />

                <label for="veste">Veste<span>35 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="jogging" name="article" value="jogging" />

                <label for="jogging">Jogging<span>27 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="chaussettes" name="article" value="chaussettes" />

                <label for="chaussettes">Chaussettes<span>7 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="gourde" name="article" value="gourde" />

                <label for="gourde">Gourde<span>7 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="2tshirt" name="article" value="2tshirt" />

                <label for="2tshirt">2 T-shirts<span>16 €</span></label>
            </div>

            <div>
                <input type="checkbox" id="ensemble" name="article" value="ensemble" />

                <label for="ensemble">Veste + Jogging<span>60 €</span></label>
            </div>
        </div>

        <div id="facturation">
            <h3>Informations de facturation</h3>

            <div class="row">
                <label for="nom">Nom et Prénom</label>

                <input type="text" name="nom" id="nom">
            </div>

            <div class="row">
                <label for="adresse">Adresse</label>

                <input type="text" name="adresse" id="adresse">
            </div>

            <div class="row">
                <label for="code">Code postal</label>

                <input type="text" name="code" id="code">
            </div>

            <div class="row">
                <label for="ville">Ville</label>

                <input type="text" name="ville" id="ville">
            </div>

            <div class="row">
                <label for="mail">Adresse mail</label>

                <input type="text" name="mail" id="mail">
            </div>

            <div>
                <input id="conf-commande" type="submit" value="Commander">
            </div>
        </div>

    <?php
    include "/commande/redirect.php";
    ?>

    </form>

I found tutorials on retrieving simple information like the first part because they're just text inputs. But I'm having trouble finding checkboxes solutions. The way I see it, I have two options :

  • Getting the checkbox value with PHP and storing it in a table column already created with MySQL
  • Finding which value is checked with PHP and adding a "yes" or number 1 in the corresponding table column already created with MySQL

However I have no idea how to handle those values with PHP, PLUS the other text inputs information needing to be on the same table line for the customer order to be correct when reading afterwards.

This is the output I have in mind : enter image description here

Unfortunately as I said, I don't know how I could get such a table. This is asking a lot, but could anyone help me if it doesn't seem too long to explain ? If not, maybe point me towards a tutorial or a place I could learn to do such a thing ? Thanks a lot !




Aucun commentaire:

Enregistrer un commentaire