0
Hello, I’m having the following mistake:
Notice: Undefined index: dataInicio in C: xampp htdocs Dashboard Dashboard.php on line 124.
Apparently I’m not making the right use of the $_POST, but I don’t know where I’m going wrong, can anyone help me? I’ll put the code to clarify how everything is being defined:
Here in PHP I get the $_POST index :
// Filtro data
$dataHumanaFim = "";
$dataHumanaInicio = "";
$dataHumanaInicio = $_POST['dataInicio'];
$dataHumanaFim = $_POST['dataFim'];
$sqlFiltroData = 'SELECT * from devices where first_time between "'.mktime($dataHumanaInicio).'" and "'.mktime($dataHumanaInicio).'"';
$filtroData = $pdo->query($sqlFiltroData);
//var_dump($filtroData);
This is where I require the values that should go for $_POST:
<form method="POST" action="dashboard.php">
<div class="col-4">
<label for="dataInicio">De:</label>
<input type="text" id="dataInicio" name="dataInicio">
<label for="dataFim">Até:</label>
<input type="text" id="dataFim" name="dataFim">
</div>
<button type="submit" class="btn btn-primary btn-alert" onclick="filtroData()" id="pesquisaFiltro" value="Pesquisa" name="submit">Pesquisar</button>
</form>
And here is the function I do in javascript/jquery for the button... :
$(function filtroData(){
//Função para filtro por data
$('#pesquisaFiltro').click(function(){
document.getElementById("filtroData").removeAttribute("hidden");
});
});
Can someone tell me where I’m going wrong or where I can verify a better way to do what I’m trying to do?
$dataHumanaInicio = $_POST['dataInicio']; the error actually happens on this line and on the 125 line: $dataHumanaFim = $_POST['dataFim'];
– Felipe Gregio
I tested here and did not error: https://repl.it/@Ronaldovasques/Insistentunequaledbytes . Error must be elsewhere.
– Augusto Vasques
Something else you don’t use
onclick
withsubmit
.– Augusto Vasques
I think I know where the error is, I’m doing everything on the same page, not separate as you show there in the test example, maybe if I play PHP in another file and change the action to that file the error sum... I’m gonna test
– Felipe Gregio
Well, I changed the action to "send.php" and put the variables there as well as in your example, and the error follows the same, only changed the location... : Notice: Undefined index: dataInicio in C: xampp htdocs Dashboard envia.php on line 7 Notice: Undefined index: dataFim in C: xampp htdocs Dashboard envia.php on line 8
– Felipe Gregio
Is the code too big? If not, send a repl.it with your code to be analyzed.
– Augusto Vasques
It’s kind of big yes, I think we can not reproduce everything in repl.it ... There is some other way ?
– Felipe Gregio
Github, but I work. I spend coffee breaks here at Stackoverflow. If it’s too big I won’t have to reconcile things.
– Augusto Vasques