How to take bank line value and put in checkbox

Asked

Viewed 482 times

0

Good morning, I have a problem here, I created a line <p> which shows me the database table data id and the hour. What I needed was to take that amount and put in value from the checkbox so you can send this information in another table the way you put the checkbox

<input type="checkbox" name="Hdisponivel[]" value="e colocava o valor da tabela aqui para poder selecionar que no caso seria o hora_de_segunda" />

my code:

<?php include("../php/agenda.php"); include("../php/alterar.php"); ?>


    <!DOCTYPE html>
    <html lang="pt-br" ng-app="AngularADM">

    <body ng-controller="TempoHorasP1">



        <div class="container">
            <div class="row">
                <h2 class="dourado texto-centro margin-top30 bold">Configuração da agenda online</h2>
            </div>

            <div class="row">

                <h3 class="texto-centro dourado">Agenda da 1º semana</h3>
                <hr />

                <div class="center-block">
                    <div class="row">

                        <div class="col-lg-3 texto-centro bloco-hora">
                            <p class="margin-top10">Segunda feira</p>
                            <hr />



                            <?php

    if($total > 0) {

        do {

?>


                                <div class="col-lg-4 texto-centro hora-banco">

                                    <p>
                                        <?=$linha['id']?>
                                    </p>

                                </div>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$linha['horas_de_segunda']?>
                                         <input type="checkbox" name="Hdisponivel[]" value="" />
                                    </p>

                                </div>


                                <?php

        }while($linha = mysqli_fetch_assoc($dados));

    }
?>

                        </div>

                        <div class="col-lg-3 texto-centro bloco-hora">
                            <p class="margin-top10">Terça feira</p>
                            <hr/>




                            <?php

    if($terc > 0) {

        do {

?>
                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$terLinha['id']?>
                                    </p>

                                </div>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$terLinha['horas_de_terca']?>
                                        <input type="checkbox" name="Hdisponivel[]" value="" />

                                    </p>

                                </div>


                                <?php

        }while($terLinha = mysqli_fetch_assoc($ter));

    }
?>

                            <input type="submit" />
                        </div>

                        <div class="col-lg-3 texto-centro bloco-hora">
                            <p class="margin-top10">Quarta feira</p>
                            <hr/>




                            <?php

    if($qua > 0) {

        do {

?>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$quarLinha['id']?>
                                    </p>

                                </div>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$quarLinha['horas_de_quarta']?>
                                        <input type="checkbox" name="Hdisponivel[]" value="" />
                                    </p>

                                </div>



    </body>


    </html>

php agenda.:

<?php
//require_once 'valida.php';
// definições de host, database, usuário e senha
include("conexao.php");

mysqli_select_db($link, $bd);

// cria a instrução SQL que vai selecionar os dados
$selecionar = "SELECT id, horas_de_segunda FROM horas_segunda";

// executa a query
$dados = mysqli_query($link, $selecionar) or die(mysqli_error($link));

// transforma os dados em um array
$linha = mysqli_fetch_assoc($dados);

// calcula quantos dados retornaram
$total = mysqli_num_rows($dados);


//segundo
$terca = "SELECT id, horas_de_terca FROM horas_terca";

$ter = mysqli_query($link, $terca) or die(mysqli_error($link));

$terLinha = mysqli_fetch_assoc($ter);

$terc = mysqli_num_rows($ter);


//terceiro

$quarta = "SELECT id, horas_de_quarta FROM horas_quarta";

$quar = mysqli_query($link, $quarta) or die (mysqli_error($link));

$quarLinha = mysqli_fetch_assoc($quar);

$qua = mysqli_num_rows($quar);

?>

How could I do, summing up all this I need to get the value of mysqli_num_rows($quar); and put in the <input type="checkbox" name="Hdisponivel[]" value="aqui dentro" />

Thank you

2 answers

1


Just give me one echo of the variable, within the value="" of input that you want.

Example

<?php   $animal = 'gato';   ?>

<input type="text" value="<?= $animal ?>" />

The variable within the "<?= ?>" is the same as "<?php echo $animal; ?>"

Try this: $hora_on = (isset( $_POST['Hdisponivel[]'] )) ? $_POST['Hdisponivel[]'] : '';

  • I did so only that my Insert is not working appears this error Notice: Undefined index: Hdisponivel in C: wamp64 www site php Horasdisponivel.php on line 11 and my line 11 is this $hora_on = $_POST['Hdisponivel[]']; could help me?

  • I did according to what you explained

  • I edited the answer. Try it there.

  • error is missing, only the data does not appear in the database

  • Ah, man, it looks like you’re a little lost in there. You made your code or copied it from somewhere?

  • I did, what I did put a form, then I created an Insert with the checkbox and taking the values that are pulled in the bank and then I tried to send with Ubmit, only the values are not going, I’ll open another question to not be confused, but dude Fight really helped here because the problem is now another.

  • Got it. Good luck there.

Show 2 more comments

0

<input type="checkbox" name="Hdisponivel[]" value="<?php echo myVar;?>" />

By defining the name with "[]" Voce you are passing an array type variable to the Post. This means you have to loop (usually a foreach) to get the value. If you want to "directly" access the Post value without the loop write like this:

<input type="checkbox" name="Hdisponivel" value="<?php echo myVar;?>" />

Browser other questions tagged

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