This is my php code:
if(isset($_POST['menu'])){
$menu = $_POST['menu'];
$dateFoundation = $_POST['date'];
$cnpj = $_POST['cnpj'];
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$link = $_POST['link'];
$site = $_POST['site'];
$facebook = $_POST['facebook'];
$instagram = $_POST['instagram'];
$googleplus = $_POST['googleplus'];
$pinterest = $_POST['pinterest'];
$stmtUpdateMoreInfo = $conn->prepare("SELECT menu.fundation_date, menu.cnpj, menu.link, address.lat, address.lng
FROM menu
LEFT JOIN public.address ON menu.address_id = address.address_id
WHERE menu_id = :menu");
$stmtUpdateMoreInfo->bindValue(":menu", $menu);
$stmtUpdateMoreInfo->execute();
$informations = $stmtUpdateMoreInfo->fetch(PDO::FETCH_OBJ);
echo'to aquii no php';
if ($informations->fundation_date !== $dateFoundation) {
$newDate = ($informations->fundation_date !== $dateFoundation) ? correctBadWords($dateFoundation) : $informations->fundation_date;
echo'variável do banco de dados? '.$informations->fundation_date;
echo'variável nova '.$newDate;
}
if ($informations->cnpj !== $cnpj) {
$newCnpj = ($informations->cnpj !== $cnpj) ? correctBadWords($cnpj) : $informations->cnpj;
echo'cnpj que está no banco de dados? '.$informations->cnpj;
echo'cnpj novo? '.$cnpj;
}
if ($informations->fundation_date !== $dateFoundation || $informations->cnpj !== $cnpj) {
$stmtUpdateInformations = $conn->prepare("UPDATE menu SET fundation_date = :date, cnpj = :cnpj WHERE menu_id = :menu");
$stmtUpdateInformations->bindValue(":date", $newDate);
$stmtUpdateInformations->bindValue(":cnpj", $newCnpj);
$stmtUpdateInformations->bindValue(":menu", $menu);
if($stmtUpdateInformations->execute()){
echo 'true';
}else{
echo'false';
}
}
This my javascript:
if (moreInformations) {
$.ajax({
url: './model/functions/more_informations.php',
type: 'POST',
data: {date: $("#date-foundation").val(), cnpj: $("#cnpj").val(),
latitude: $("#latitude").val(), longitude: $("#longitude").val(),
link: $("#link").val(), site: $("#site").val(), facebook: $("#facebook").val(),
instagram: $("#instagram").val(), googleplus: $("#googleplus").val(), pinterest: $("#pinterest").val(),
menu: $("#menuid").val()},
success: function (data) {
alert('to aqui'+data);
if(data === 'true'){
location.reload(true);
}else{
alert('deu pau');
}
}
});
}
});
How do I do when to execute my bank command, page reload? What should I put in the ajax return? And I have one more question, in my php file, when one of the things change or the date or the cnpj I enter the command and update, if nothing changes nothing does, and if one changes the other remains the same. How to make others stay the same? It takes and is leaving null when it updates one and does not update the other one.