Search code examples
phpandroidmysqlmamp

Im trying to retrieve data from mysql with MAMP


hi guys I'm trying to retrieve data from mysql server with php, but the variable with YYYY-MM-DD it not working without date variable it works, anyone know what happened ?

If I try do in MAMP command line work but sending data from url no, please help thanks

pd: sorry for my english and on my local server date value its a date type thanks

http://localhost/arriendo/Hora.php?centroid=111&cancha=1&date=2015-11-22

$cod=$_GET["centroid"]; $cancha=$_GET["cancha"]; $date=$_GET["date"];

$result = mysqli_query($con,"SELECT Hora FROM reserva3 WHERE Cod_centro='$cod' AND Cancha='$cancha' AND Fecha='$date'");


Solution

  • To see what is wrong with your query try debugging it Here's how I debug query's

    1. echo the query to the screen

      $query= "SELECT Hora FROM reserva3 WHERE Cod_centro='$cod'  AND Cancha='$cancha' AND Fecha='$date'";
      echo $query;
      
    2. copy the printed query from the screen

    3. execute the query in you db manager (phpmyadmin)

    4. Read the sql error and

    5. change your query accordingly

    Assumming you have a timestamp (not only date) I think you can change your query from

    SELECT Hora FROM reserva3 WHERE Cod_centro='$cod'  AND Cancha='$cancha' AND Fecha='$date'
    

    to

    SELECT Hora FROM reserva3 WHERE Cod_centro='$cod'  AND date(Cancha)='$cancha' AND Fecha='$date'
    

    If this works it's because of formatting why the first query didn't work. otherwise you have to add your sql error here, so we can fix.