2
I wanted to send the message of success or error after registering products from my site on the same page, without loading a new blank with the message, I saw similar questions, some using ajax that have not learned anything yet and could not solve my problem with the topics I found here.
Register of Category:
<form method="post" action="gravacategoria.php">
<div class="container">
<div class="form-group">
<label class="col-md-4 control-label" for="txtproduto">Nova Categoria: </label>
<div class="col-md-6">
<input id="txtcategoria" name="txtcategoria" type="text" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="btnsalvar"></label>
<div class="col-md-8">
<button id="btnsalvarcat" name="btnsalvar" type="Submit" class="btn btn-primary">Salvar</button>
<button id="btncancelar" name="btncancelar" class="btn btn-danger">Cancelar</button>
</div>
</div>
</div>
</form>
Gravacategoria:
<?php
$conn= new PDO("mysql:host=localhost:3306;dbname=loja","root","aula");
#$idcategoria=$_POST["txtid"];
$nomecat=$_POST["txtcategoria"];
$stmt = $conn->prepare('Insert into loja.categoria(nome)Values(:par_categoria)');
#$stmt->bindValue(1,$idcategoria);
$stmt->bindValue(2,$nomecat);
$dados=array(":par_categoria"=>$nomecat);
$result = $stmt->execute($dados);
if($result){
echo ("Produto inserido com sucesso");
}
else{
echo("Erro");
}
Thank you!
Well, the solution is, in fact, with AJAX. Start by studying it. There are functions like
fetch
Javascript or libraries like Jquery, Axios, among others, that can make your life easier. Good luck.– Woss