With this, but using it with all the other variables, you can ensure that it exists and is not empty, so we are discarding options until we reach the solution.
if (isset($_POST["sexo"]) && isset($_POST["nombre"]) && !empty($_POST["sexo"]) && !empty($_POST["nombre"]) ){
$nombre=$_POST["nombre"];
$sexo=$_POST["sexo"];
}
Now it would be great if you could pass the data as arguments of the function
something like this, it has happened to me that the functions do not recognize the variables that are not inherent to itself only if they are decalitated as global or public, my solution to pass them to the function as arguments.
if (isset($_POST["sexo"]) && isset($_POST["nombre"]) && isset($_POST["identificacion"]) && isset($_POST["telefono"]) && isset($_POST["password"]) && isset($_POST["correo"]) && isset($_POST["rol"]) && isset($_POST["fecha"]) && !empty($_POST["sexo"]) && !empty($_POST["nombre"]) && !empty($_POST["identificacion"]) && !empty($_POST["telefono"]) && !empty($_POST["password"]) && !empty($_POST["correo"]) && !empty($_POST["rol"]) && !empty($_POST["fecha"]) )
{
$identificacion=$_POST["id"];
$nombre=$_POST["nombre"];
$sexo=$_POST["sexo"];
$password=123;
$telefono=$_POST["telefono"];
$correo=$_POST["correo"];
$rol=2;
$fecha=$_POST["anio"].$_POST["mes"].$_POST["dia"];
agregado($identificacion,$nombre,$sexo,password,$telefono,$correo,$rol,$fecha);
}
function agregado($identificacion,$nombre,$sexo,password,$telefono,$correo,$rol,$fecha ){
$query="INSERT INTO paciente VALUES('$identificacion','$nombre','$sexo','$password',
'$telefono','$correo','$rol','$fecha')";
$agregarPaciente = mysqli_query($conexion,$query);
}