I have this form and script on a page:
<section class="hide-section" id="produto_1">
<form class="form-validate" id="feedback_form">
<div class="campo">
<fieldset>
<h1>
<legend>
<center>
<strong>Produtos de Higiene</strong>
</center>
</h1><br>
</div>
<fieldset class="grupo">
<div class="campo">
<strong><label for="Nome do Produto">Nome do Produto</label></strong>
<input type="text" id="DescricaoProd" name="DescricaoProd" required="" style="width:350px">
</div>
<div class="campo">
<strong><label for="Unidade">Unidade</label></strong>
<input type="text" id="DescricaoUnid" name="DescricaoUnid" style="width:160px" required="" size="120">
</div>
</fieldset>
<button class="btn btn-success btn_contact" type="button">Registo</button>
</form>
</section>
<script type="text/javascript">
$(".btn_contact").click(function () {
$.ajax({
type: "POST",
url: "./inserir",
data: $("#feedback_form").serialize(), // serializes the form's elements.
success: function (data)
{
if ($.trim(data) == 'true') {
$("#feedback_form").find('input').val(''); //clear text
$(".success_messages").removeClass('hide'); // success message
} else {
$(".error_message").removeClass('hide'); // error message
}
}
});
});
</script>
On the insert page I have this php code:
$name = isset($_POST["DescricaoProd"]) ? $_POST["DescricaoProd"] : '';
$unid = isset($_POST["DescricaoUnid"]) ? $_POST["DescricaoUnid"] : '';
if (!empty($name) && !empty($unid)) {
echo 'true';
} else {
echo 'false';
}
$sql = "INSERT INTO ProdHigieneteste (DescricaoProd,DescricaoUnid)
VALUES ('$name','$unid')";
if ($conn->query($sql)) { // check for === TRUE is not necessary
// either put the second query in here, or just enjoy the success
} else {
// get the error, throw a message...
}
$sql1 = "INSERT INTO StockHigieneteste (DescricaoProd,DescricaoUnid)
VALUES ('$name','$unid')";
if ($conn->query($sql1) === TRUE) {
//Count total number of rows
$rowCount = $query->num_rows;
} else {
// get the error, throw a message...
}
$conn->close();
I was inserting into the database table and stopped inserting, but it also does not give any errors in the console. Can anyone help identify the problem?