0
I have a code to update and delete data in the database so that unfortunately it shows the custom Alert on the screen so it does not write to the database and does not update the bad page but save so it does not show the custom Alert.
I’m using alertigo.js
and modal.
Is there any way to do so when updating data or deleting it shows this custom Alert and saves the data in the database? I’ve done so much research and I haven’t found anything that could help me.
<div class="modal fade" id="add_evento" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Funcionario</h4>
</div>
<div class="modal-body">
<div class="panel-group">
<div class="panel panel-default ">
<div class="panel-heading funcionario"></div>
<div class="panel-body funcao">Panel Content</div>
</div>
</div>
<form method="POST" id="myForm" enctype="multipart/form-data">
<input type="hidden" name="id_func" id="id_func">
<input type="hidden" name="nome" id="nome">
<input type="hidden" name="funcao" id="funcao">
<div class="form-group">
<label for="recipient-residente" class="control-label">Residência (Sua residência atual):</label>
<input type="text" class="form-control" name="residente" id="residente" >
</div>
<div class="form-group">
<label for="recipient-naturalidade">Natural de:</label>
<select class="form-control" id="naturalidade" name="naturalidade">
<option value="Luanda">Luanda</option>
<option value="Cabinda">Cabinda</option>
<option value="Benguela">Benguela</option>
<option value="Huila">Huíla</option>
</select>
</div>
<div class="form-group">
<label for="recipient-residente" class="control-label">Trocar a foto</label>
<input type="file" name="foto" multiple id="ssi-upload" class="form-control"/>
</div>
<div class="form-group">
<label for="description">Quem Você é:</label>
<textarea class="form-control" rows="5" id="description" name="description"></textarea>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-info">Alterar</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
</div>
</form>
</div>
</div>
</div>
</div>
AJAX Code
$(document).ready(function(){
$('#myForm').submit(function (e) {
e.preventDefault();
var productId = $('#myForm').serialize();
$.ajax({
type: "POST",
url: "update_func.php",
data: productId,
success:function(productId){
alertigo('This is a LIGHT-BLUE alertigo.js notification message!', {color: 'light-blue'});
}
});
});
});
Redirecting to PHP
$panel_atual = "funcionario";
require "../config.php";
$id = intval($_POST['id_func']);
$nome = $_POST['nome'];
$naturalidade = $_POST['naturalidade'];
$residente = $_POST['residente'];
$description = $_POST['description'];
$imgvar_func = $_FILES['foto']['name'];
if (file_exists("img_func/$imgvar_func")) {
$a = 1;
while (file_exists("img_func/[$a]$imgvar_func")) {
$a++;
}
$imgvar_func = "[".$a."]".$imgvar_func;
}
$result_edit = "UPDATE funcionarios SET naturalidade='$naturalidade', residente='$residente', description = '$description', imagem = '$imgvar_func' WHERE id='$id_func' AND nome='$nome'";
$resultado_edit = mysqli_query($conexao, $result_edit);
(move_uploaded_file($_FILES['ssi-upload']['tmp_name'], "img_func/".$imgvar_func));
if ($resultado_edit) {
echo "<script type='text/javascript'>window.alert('Dados alterados com sucesso!');window.location='index.php';</script>";
}else{
echo "<script type='text/javascript'>window.alert('oops! Houve um problema. Tente novamente, por favor!');window.location='index.php';</script>";
}
The update_func.php file is in the same folder?
– Sveen
Yes this in the same folder
– Jose Pinto