get a value of a function in javascript and send it to php to make a query in mysql

0

Good day, I'm doing a calendar in php that when clicking on a day of the month, show me in a window if on that date there is some data stored in my database. I use javascript to tell me which day was selected but I do not know how to send that value to php and then ask the question, could someone please guide me.

I add part of my code, the calendar works well for me,

<script type="text/javascript">
function dias_x(dia)
{
    var a=1;
    var dia;
    for(a=1;a<32;a++)
    {
        if(dia==a)
        {
            alert("Eventos del dia: "+dia);
        }
    }
return dia;
}
</script>

 <?php
//include 'variable.php';
$dias=1;
//dibujamos las celdas por mes seleccionado
for($i=1;$i<=$cantidad_dias;$i++)
{
//si la semanana no empieza en domingo corremos celdas
    if ($i <= $saltear_casillas)
    {
        echo '<td>-</td>';  
    }
    else
    {
        $num_dia=$i-$saltear_casillas;
        if($num_dia==$diaActual)
        {
            echo "<td class='hoy' onclick='dias_x($num_dia)' bgcolor='#f7dc6f' id='diaActual' onmouseover='cambiacolor_over(this)' onmouseout='cambiacolor_out(this)'>$num_dia</td>";
            $val2="$num_dia";
        }
        else
        {
            echo "<td  class='dia' onclick='dias_x($num_dia)' id='otro_dia'onmouseover='cambiacolor_over(this)' onmouseout='cambiacolor_out(this)' >$num_dia</td>";
            $num_dia++;
        }   
    }
    if($i%7==0)
    {
        echo'</tr><tr>';
    }
}
//escribir las celdas vacias
for($i=1;$i<=$diferencia;$i++)
{
    echo '<td>-</td>';
}
// empiexa para el popup

include 'conexion.php';
$fecha1=$numero_anio.'-'.$numero_mes.'-'.$diaActual;
$currentDate = $numero_anio.'-'.$numero_mes.'-'.$dias;
$venNum=0;
$resultado=mysqli_query($connection,"SELECT nombre FROM eventos");

$evenNum =mysqli_num_rows($resultado);//mostrar cuantos datos hay almacenados en mi bd
echo $evenNum," cantidad de registros en la bd";
echo "<br>";
echo "Fecha de hoy"." ".$fecha1; //fecha de hoy
echo "<br>";
echo $currentDate;

include 'cerrarconexion.php'; //cerramos la conexion

?> 
    
asked by Gabriel_003 09.07.2018 в 03:14
source

1 answer

0

The fastest way that I use is using jquery

and using the ajax function as follows

$(document).ready(function(){       
    $('#btn-ingresar').click(function(){
        var url = "datos_login.php";
        $.ajax({                        
           type: "POST",                 
           url: url,                     
           data: $("#formulario").serialize(), 
           success: function(data)             
           {
             $('#resp').html(data);               
           }
       });
    });
});

in the php file you can receive it like this.

<?php   
    $usuario = $_POST['usuario'];
    $contra  = $_POST['contrasena'];

    echo "tu usuario es: ".$usuario; 
    echo "contraseña es: ".$contrsena;
?>

now you can do whatever you want with the data in php.

I remain attentive to any questions.

    
answered by 20.11.2018 в 18:43