<?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_ord=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['id_ord']))) ;
$id_consult=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['id_consult']))) ;
$nom_med=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['id_medicament']))) ;
$quantite=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['quantite']))) ;
$posologie=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['posologie']))) ;



$sql2 = "INSERT INTO medicaments (nom_med,quantite,posologie) VALUES 
								   ('$nom_med','$quantite','$posologie') ";

$result2=mysqli_query($con,$sql2) or die('Query privacy_stars failed: ' . mysqli_error($con));


if ($result2) {
$id_med = mysqli_insert_id($con);
$sql3 = "INSERT INTO ordonnance_medicament(id_ord, id_med) VALUES ('$id_ord','$id_med')";
$result3=mysqli_query($con,$sql3) or die('Query privacy_stars failed: ' . mysqli_error($con));
}else{
        echo "Error: " . $query . "<br>" . mysqli_error($con);
    }
 if($result2){
  echo 1;
  } else {
echo 0;
 }
 

    }

?>