Error writing date converted to phpMyAdmin database

0

I'm trying to write a form to the database, in that form there's a date field that contains dd/mm/aaaa mask. To write to the bank I need to convert that date to aaaa-mm-dd , until then I got str_replace , the problem is that when I write this variable in the bank it returns me an error and does not record anything in the bank. Follow me code:  

<form action="envia.php" method="post" enctype="multipart/form-data">
        <div class="form-row">
            <div class="form-group col-md-6">
                <label class=""><b>Sistema</b></label>
                    <select name="sistema" class="form-control" required/>
                        <option selected>Escolha o sistema</option>
                        <option value="ATPH">ATPH </option>
                        <option value="DPPH">DPPH Pagamento</option>
                        <option value="EFPH">EFPH </option>
                        <option value="SCPH">SCPH</option>
                        <option value="GEPH">GEPH</option>
                        <option value="BICLI">BIPH</option>
                        <option value="BISER">BIPH</option>
                    </select>

            </div>

            <div class="form-group col-md-6">
                <label class=""><b>Data</b></label>
                <input type="text" name="data" class="form-control" maxlength="10" onkeypress="mascaraData(this)" placeholder="Digite a data da Revisão" required/>
            </div>  

            <div class="form-group col-md-6">   
                <label class=""><b>Versão</b></label>
                <input type="text" name="versao" class="form-control" placeholder="Digite a Versão" required/>
            </div>

            <div class="form-group col-md-6">
                <label class=""><b>Revisão</b></label>
                <input type="text" name="revisao" class="form-control" placeholder="Digite a Revisão" required/>    
            </div>  

            <div class="form-group col-md-12">
                <label class=""><b>Arquivo</b></label>
                <input type="file" name="arquivo" class="form-control" required/>
            </div>

            <div class="form-group col-sm-2">
                <div class="">
                    <button type="submit" class="btn btn-primary upload">Enviar</button>
                </div>
            </div>
        </div>
    </form>  



    
asked by anonymous 07.11.2018 / 14:17

2 answers

1

I think your problem is just how you entered the variables in the string that will be sent to the bank. Try this:

$query = "INSERT INTO ".$table." (versao, revisao, data) VALUES ('".$versao."', '".$revisao."', '".$data."')";

It's ugly, it's annoying to write, but I think it solves the problem. The values must be within 'quotes' but since it comes from a variable it needs to be outside a string, then you close the string and concatenate the values one by one.

    
08.11.2018 / 05:13
1

If you are correctly printing the date value, have the variable receive this value. See:

$data = date('Y-m-d', strtotime($data));

Of course, after you have used str_replace

    
07.11.2018 / 14:26