A checkbox can have more than one value?

Asked

Viewed 197 times

-3

I wonder if a checkbox can have more than one value example type below for one with the name of the checkbox and another with the price . I am grateful already.

<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Bolinho" value="15.75">Bolinho</td>
  • 2

    No ..., what would be your problem?

  • well in my form it has only the name of the meal which is inserted in mysql, and then I take it and I display all the order on another screen , but I wanted to put the price too so I can take the total value also of the order .

  • Well, if you can solve your problem in many ways, you need a bigger context. Working with two values and one tag I’ve never really seen.

  • No field can have more than one value, but nothing prevents you from putting more than one value value="pipoca|3.75" and split on the server side later. The case is that you should not need this, because if you are generating the page yourself, on the server side you already know which ID or field name is which product.

  • yes more type, when I send the form on the server have the requested columns, quantity and value , so could show on screen the total value of the order and what was requested .

  • 2

    you can use the field data-*

  • You already have it on the server, you don’t have to send it back.

  • @Marcelobonifazio what he does ? date-*

  • Alan, I do not think that this question deserved negative, because I think it is a valid doubt and other users can benefit from it, however their doubt in reality, its doubt is wide and goes from the front-end(html) to the back-end(php/mysql). I see you with some doubts that can be solved here, but explain where you want to go and mainly study the fundamental concepts of these operations, in this case CRUD, try to understand the basics(CREATE/READ/UPDATE/DELETE - Insert/Select/Update/Delete)

  • which are exactly the columns of your table?

  • meal, quantity, drink, quantity, and I want to put the price with the total amount. @Leocaracciolo

  • if you have 2 meals on a bench table will save in two rows?

  • type have customer ordering multiple meals and they are saved in the same line . and the amount in the same way but in another line , and so on.

  • is confusing this. Your table columns are meal, quantity, drink, quantity. How to save multiple meals in the same row and quantities in another row in that table structure?

  • see if the answer suits you

  • @Leocaracciolo I can’t find the code you made of the request related to this question http://answall.com/questions/181148/comort-dataos-para-o-mysql-via-javascript?noredirect=1#comment374523_181148

Show 11 more comments

1 answer

1


I think what you want is this:

PHP

if (isset($_POST["numero_mesa"])) {

        $link = new mysqli ("localhost", "USUARIO", "SENHA", "DB");
        if($link->connect_errno){
             echo"Nossas falhas local experiência ..";
             exit();
        }
        $numero_mesa=$_POST["numero_mesa"];

        foreach($_POST as $nome_campo => $valor){ 
            if(($nome_campo != "numero_mesa")&&($valor!="")){
                $nome_campo=str_replace("-"," ",$nome_campo);
                $aDest = explode("*", $nome_campo); 
                $nome_c=$aDest[0];
                $preco=$aDest[1];

                $sql = "INSERT INTO spedido(numero_mesa,pedido,quantidade,preco) VALUES('$numero_mesa','$nome_c','$valor','$preco')";
                $resultado_pedido = mysqli_query($link,$sql);
            }

        }
}

HTML

<!DOCTYPE html> 
<html>
    <head>
        <title>Peixaria</title>
        <script type="text/javascript"> <!-- function valida_form (){ if(document.getElementById("numero_mesa").value.length ==""){ alert('Por favor, preencha o campo Mesa'); document.getElementById("numero_mesa").focus(); return false } } //--> </script> 
    </head>
    <body>
        <h1>Peixaria</h1>
        <main>
            <header>
                <h2>Fazer Pedido</h2>
            </header>
            <fieldset>
                <div class="pedidos">
                    <form method="post" action="pedidos.php" onsubmit="return valida_form(this)">
                        <table border="0" id="table1">
                            <tr>
                                <td colspan="4" width="100"> <span>Mesa</span> <input type="text" id="numero_mesa" name="numero_mesa"> </td>
                            </tr>
                            <tr>
                                <td width="280" bgcolor="#FFEBC1">Refeição</td>
                                <td width="70" bgcolor="#FFEBC1">Quantidade</td>
                                <td width="150" bgcolor="#DFFFDF">Bebida</td>
                                <td width="70" bgcolor="#DFFFDF">Quantidade</td>
                            </tr>
                            <tr>
                                <td width="280">Costela de Tambaqui sem Espinha</td>
                                <td width="70"><input type="text" name="Costela-de-Tambaqui-sem-Espinha*20.00" size="7"></td>
                                <td width="150">Fanta Laranja 1l</td>
                                <td width="70"><input type="text" name="Fanta-Laranja-1l*8.00" size="7"></td>
                            </tr>
                            <tr>
                                <td width="280">Lombo de Tambaqui Frito sem Espinha</td>
                                <td width="70"><input type="text" name="Lombo-de-Tambaqui-Frito-sem-Espinha*22.00"size="7"></td>
                                <td width="150">Fanta Laranja 2l</td>
                                <td width="70"><input type="text" name="Fanta-Laranja-2l*10.00" size="7"></td>
                            </tr>
                            <tr>
                                <td width="280">Caldeirada de Tambaqui sem Espinha</td>
                                <td width="70"><input type="text" name="Caldeirada-de-Tambaqui-sem-Espinha*30.00" size="7"></td>
                                <td width="150">Cola Cola 1l</td>
                                <td width="70"><input type="text" name="Cola-Cola-1l*12.00" size="7"></td>
                            </tr>
                            <tr>
                                <td width="280">Caldeirada de Tucunaré</td>
                                <td width="70"><input type="text" name="Caldeirada-de-Tucunaré*32.00" id="q4" size="7"></td>
                                <td width="150">Cola Cola 2l</td>
                                <td width="70"><input type="text" name="Cola-Cola-2l*14.00" size="7"></td>
                            </tr>
                            <tr>
                                <td width="280">Peixe no Tucupi com Camarão</td>
                                <td width="70"><input type="text" name="Peixe-no-Tucupi-com-Camarão*35.00" size="7"></td>
                                <td width="150">Bare 2l</td>
                                <td width="70"><input type="text" name="Bare-2l*8.00" size="7"></td>
                            </tr>
                            <tr>
                                <td colspan="4" width="100"> <button class="btn" type="submit">Fazer Pedido</button> </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </fieldset>
        </main>
    </body>
</html>
  • you have to place a price column in the Bank and input Names in html should be composed according to this example: name="Rib-de-Tambaqui-without-Spina*20.00" , that is, replace spaces by tracine - in the names of meals and beverages followed by their prices separated by an asterisk *

Browser other questions tagged

You are not signed in. Login or sign up in order to post.