<?php session_start();
if(!empty($_SESSION['user_connect_id']))
{ require('../../config.php');

date_default_timezone_set('Africa/Algiers');
$d_aj=date('Y-m-d H:i:s');
$id=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['id']))) ;
$nom=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['nom']))) ;
$prenom=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['prenom']))) ;
$sexe=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['sexe']))) ;
$date_naissance=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['date_naissance']))) ;
// calculer age à partir de la date de naissance
$dateOfBirth =date("Y-m-d", strtotime($date_naissance));
$today = date("Y-m-d");
$diff = date_diff(date_create($dateOfBirth), date_create($today));
$age= "".$diff->y."ans et ".$diff->m."mois ";
$groupe_sanguin=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['groupe_sanguin']))) ;
$situation_familiale=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['situation_familiale']))) ;
$mail=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['mail']))) ;
$adresse=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['adresse']))) ;
$tel=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['tel']))) ;
$antecedents_med=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['antecedents_med']))) ;
$antecedents_chirur=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['antecedents_chirur']))) ;
$antecedents_famil=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['antecedents_famil']))) ;
$antecedents_autres=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['antecedents_autres']))) ;

$sql1 = "UPDATE patients SET
        nom='$nom',
        prenom='$prenom',
        sexe='$sexe',
        date_naissance='$date_naissance',
        age='$age',
        groupe_sanguin='$groupe_sanguin',
        situation_familiale='$situation_familiale',
        mail='$mail',
        adresse='$adresse',
        tel='$tel',
        antecedents_med='$antecedents_med',
        antecedents_chirur='$antecedents_chirur',
        antecedents_famil='$antecedents_famil',
        antecedents_autres='$antecedents_autres',
        date_modification='$d_aj'
        where id='$id'";
        
            if(mysqli_query($con,$sql1)){echo 1; }else{
              echo 0;
               }
    }

?>
       
