0
I am trying to write a form in the database, in this form has a date field that contains mask dd/mm/aaaa
. To record in the bank I need to convert that date to aaaa-mm-dd
, so far I’ve managed str_replace
, the problem is that when I go to record this variable in the bank it returns me an error and does not write 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>
Have you tried to var_dump the $query variable, just to make sure that during the application it is receiving the parameters correctly? By the way, now I noticed something, the formatting vc uses in echo and not in variable. That is your variable is only recorded 07-11-2018 for example.
– Rafael
Dude, so what I tried to do was the guy below responded, and I put an echo to read the
($data)
, According to the print (http://prntscr.com/lfhn8i) it reads the date in the correct format, but falls on the same Lse below and does not write. I’m half beginner in sql, how can I use this var_dump ?– lucasecorrea
var_dump would be in php itself, below your query do so:
var_dump($query);
Ai comments the line of the result and if. Ai only makes the impression of this var_dump on the screen to see how it is receiving the query– Rafael
(http://prntscr.com/lfhvgn). Is that right? Print nothing on canvas.
– lucasecorrea
UPDATING: I found an array on the internet that converts this date, conf rme print : ( http://prntscr.com/lfiqyc ). After this change, I tried to send it to the bank, it returns this message ( http://prntscr.com/lfiqgw ) which is
o echo ($query);
, and does not record anything in the bank and returns the same LSE as before. I still haven’t found a solution.– lucasecorrea
Sorry for the delay my dear, I was on the street all afternoon. Interesting, apparently your variable is receiving correctly. The first 2 values "version" and "review" are recording normally in the database?
– Rafael
I did the tests here, I think it is the format of string that is disturbing, put everything between parentheses leave your query like this:
$query = "INSERT INTO $table (versao, revisao, data) VALUES ('$versao', '$revisao', '$data')";
– Rafael
I did, with the guy’s answer down there, but thank you very much for your help
– lucasecorrea