#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    0

    Pdo prepared statement with Ajax


    Hi, not sure if this should go in php or javascript.

    I have a script in mysql deprecated wich uses Ajax.
    I have redone the script to pdo (with some small changes for other purpuses) however Ajax does no longer works....

    I have tried everything.
    I have a form that includedes a php page with queries, a javascript file wich open the php page.
    It does not work.
    In order to find out on wich page the bug is, I changed the included php file for another file that uses mysql deprecated and also called this file in the ajaxscript.
    Doing this it works, but I need to clean cache between.

    Using the same query with pdo nothing happens, only the echos and the var dumps are printed on screen.
    Desactiving javascript the pdo page works.
    Could it be due to that I had to use several names for the same vars in the query or
    could it be due that the page in first place get the var propiedad by get, uses get in the action however also pass the var propiedad in an input by post?
    Thats the only differences I can see between the one that works and the one that doesn´t.

    This is the formaction:
    <form name="solicitud" id="solicitud" class="formenquirer" method="post" action="ajaxbookingchoices.php?propiedad=<?php echo $propiedad; ?>">
    I pass in a hidden value the var propiedad also.

    This is the php, the echos are printed correctly and the try catch does not show any errors:
    PHP Code:
    if ($salida $llegada){
        echo 
    $salida;
        echo 
    $llegada;
        echo 
    $propiedad;
        
    var_dump($_POST);
    //miramos si disponible
    try {
        echo 
    "test";
    $query $dbh->prepare("SELECT DATE_FORMAT(llegada, '%e %b %Y') as lleg, DATE_FORMAT(salida, '%e %b %Y') as sal,tiporeserva, propiedad, TO_DAYS(:salida) - TO_DAYS(:llegada) as dias from bookings where ( propiedad = :propiedad )
    AND ((:llegada2 BETWEEN llegada AND date_sub(salida, interval +1 day)) 
    or (:salida2 BETWEEN date_sub(llegada, interval -1 day) AND salida) or (llegada <= :llegada3 AND salida >= :salida3) or (llegada >= :llegada4 AND salida <= :salida4))"
    );
    $query->execute(array(
     
    'salida' => $salida
         
    'llegada' => $llegada
       
    'propiedad' => $propiedad
        
    'llegada2' => $llegada
        
    'salida2' => $salida
        
    'llegada3' => $llegada
            
    'salida3' => $salida
        
    'llegada4' => $llegada
        
    'salida4' => $salida
        
    )); 
    }
    catch(
    Exception $e){
    echo 
    $e->getMessage();

    Last edited by newtonperri; February 11th, 2014 at 05:45 AM.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    the question is: What should the query do? I don't see you using it.

    Also note that PDO doesn't throw exceptions unless you explicitly set the PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION. By default, it doesn't do anything and only sets an internal error code.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    the question is: What should the query do? I don't see you using it.

    Also note that PDO doesn't throw exceptions unless you explicitly set the PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION. By default, it doesn't do anything and only sets an internal error code.
    As i said,
    the query works desactivating javascript, so the query is correct using only php.
    The query is the first query of several queries.
    First if end date (salida) is mayor than start date (llegada) is checked, if true, script continues, and it does. Until here no problem.
    The query checks availability, and if available the script continues.
    However using Ajax the query is not ejecuted at all, it print perfectly that the end date is mayor than start date.
    Not sure what to try next, I have reduced the query using only query, one var, and still the same.

    This is printed so the vars are ok:
    IN echo:
    2014-02-192014-02-01Banana_Beach_1FE
    In var_dump($_POST);:
    array(6) { ["propiedad"]=> string(16) "Banana_Beach_1FE" ["enviar"]=> string(25) "[object HTMLInputElement]" ["day"]=> string(2) "01" ["day2"]=> string(2) "19" ["month"]=> string(7) "2014-02" ["month2"]=> string(7) "2014-02" }
    In if try{ echo test
    Last edited by newtonperri; February 11th, 2014 at 08:25 AM.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Well, the query must be doing something, right? So what is that? What's the return value of execute()?
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    0
    Originally Posted by Jacques1
    Well, the query must be doing something, right? So what is that? What's the return value of execute()?
    It does, as I said, it checks availability, if not available a message is shown, if available the script continues, doing several queries,
    but as I said,
    it works perfect if javascript is disabled, and if I change the include to an include with normal mysql queries I have on site, waiting to be switched to pdo, it works perfect.
    I past the full php, however its very long and heavy, but as I said, the queries are correct:

    Edited, I cant past the full script as it is too long.
    I will try to separate the query from the rest on a separate test file and come back in a couple of hours.
    Thanks for your interest
    Last edited by newtonperri; February 11th, 2014 at 09:44 AM.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    I asked you a concrete question. And I expect a concrete answer to this question.

    You can stop repeating your stuff as if I was imbecile. I got it. But your vague descriptions don't help us one bit. I need hard facts.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    0
    Originally Posted by Jacques1
    I asked you a concrete question. And I expect a concrete answer to this question.

    You can stop repeating your stuff as if I was imbecile. I got it. But your vague descriptions don't help us one bit. I need hard facts.
    sorry,
    As far as I see I told you,
    if false the script continues, else an error is showned. It checks with the database if dates are occupied or free.
    I past part of the code:
    PHP Code:
    if ($salida > $llegada){
        echo $salida;
        echo $llegada;
        echo $propiedad;
        var_dump($_POST);
    //check if availabe
    try {
        echo "test";
    $query = $dbh->prepare("SELECT DATE_FORMAT(llegada, '%e %b %Y') as lleg, DATE_FORMAT(salida, '%e %b %Y') as sal,tiporeserva, propiedad, TO_DAYS(:salida) - TO_DAYS(:llegada) as dias from bookings where ( propiedad = :propiedad )
    AND ((:llegada2 BETWEEN llegada AND date_sub(salida, interval +1 day)) 
    or (:salida2 BETWEEN date_sub(llegada, interval -1 day) AND salida) or (llegada <= :llegada3 AND salida >= :salida3) or (llegada >= :llegada4 AND salida <= :salida4))");
    $query->execute(array(
     ':salida' => $salida
         , ':llegada' => $llegada
       , ':propiedad' => $propiedad
        , ':llegada2' => $llegada
        , ':salida2' => $salida
        , ':llegada3' => $llegada
            , ':salida3' => $salida
        , ':llegada4' => $llegada
        , ':salida4' => $salida
        
    )); 
    }
    catch(Exception $e){
    echo $e->getMessage();
    }
    $query->setFetchMode(PDO::FETCH_OBJ);
         if ($row = $query->fetch()) {
           if ($row->tiporeserva=="larga"){ echo "<p>This property is available only for long term rentals, consult us for a price.</p>
    "; } 
    else { 
    $propiedad = str_replace("_", " ", $propiedad); 
    echo "<p>$propiedad is not available from $arrival_display to $departure_display.</p>"; 
    echo "<p>$propiedad is occupied from ". $row->lleg ." until ". $row->sal ."</p>"; 
    }
     
    ?>
    <p>Check and calculate other dates:<br>(Different months can have different prices)</p>

    <?php
    }//end check if available
    else{
    $query $dbh->prepare("SELECT llegada, salida, propiedad, TO_DAYS(:salida) - TO_DAYS(:llegada) as dias from bookings where ( propiedad = :propiedad ) AND ((llegada = :salida2) OR (salida = :llegada2))");
    $query->execute(array(
     
    'salida' => $salida
          
    'llegada' => $llegada
           
    'propiedad' => $propiedad
    'salida2' =>$salida
        
    'llegada2' => $llegada
    )); 
    foreach (
    $query as $rows) { $dias=$rows['dias']; } 
    if (
    $salida==$rows['llegada']){  

    if (
    $dias>=7){
    $result $dbh->prepare("SELECT 
    (CASE WHEN ('
    $llegada' BETWEEN nov_inicio AND nov_fin and '$salida' BETWEEN nov_inicio AND nov_fin) 
    THEN sum(novbr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada')) ELSE NULL END) AS price,
    (CASE WHEN ('
    $llegada' BETWEEN nov_inicio AND nov_fin and '$salida' > nov_fin) 
    THEN sum(novbr) * (TO_DAYS(dec_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price1,
    (CASE WHEN ('
    $llegada' < nov_inicio and '$salida' BETWEEN nov_inicio AND nov_fin) 
    THEN sum(novbr) * (TO_DAYS('
    $salida') - TO_DAYS(nov_inicio))ELSE NULL END) AS price2,

    (CASE WHEN ('
    $llegada' BETWEEN dec_inicio AND dec_fin and '$salida' BETWEEN dec_inicio AND dec_fin) 
    THEN sum(decbr) * ( TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price3,
    (CASE  WHEN ('
    $llegada' BETWEEN dec_inicio AND dec_fin and '$salida' > dec_fin) 
    THEN sum(decbr) * (TO_DAYS(nav_inicio)- TO_DAYS('
    $llegada'))ELSE NULL END) AS price4,
    (CASE WHEN ('
    $llegada' < dec_inicio and '$salida' BETWEEN dec_inicio AND dec_fin) 
    THEN sum(decbr) * (TO_DAYS('
    $salida') - TO_DAYS(dec_inicio))ELSE NULL END) AS price5,

    (CASE WHEN ('
    $llegada' BETWEEN nav_inicio AND nav_fin and '$salida' BETWEEN nav_inicio AND nav_fin) 
    THEN sum(navbr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price6,
    (CASE WHEN ( '
    $llegada' BETWEEN nav_inicio AND nav_fin and '$salida' > nav_fin) 
    THEN sum(navbr) * ( TO_DAYS(enero_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price7,
    (CASE WHEN ('
    $llegada' < nav_inicio and '$salida' BETWEEN nav_inicio AND nav_fin) 
    THEN sum(navbr) * (TO_DAYS('
    $salida')  - TO_DAYS(nav_inicio))ELSE NULL END) AS price8,

    (CASE WHEN ('
    $llegada' BETWEEN enero_inicio AND enero_fin and '$salida' BETWEEN enero_inicio AND enero_fin) 
    THEN sum(enerobr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price9,
    (CASE WHEN ('
    $llegada' BETWEEN enero_inicio AND enero_fin and '$salida' > enero_fin) 
    THEN sum(enerobr) * (TO_DAYS( feb_inicio)- TO_DAYS('
    $llegada'))ELSE NULL END ) AS price10,
    (CASE  WHEN ('
    $llegada' < enero_inicio and '$salida' BETWEEN enero_inicio AND enero_fin) 
    THEN sum(enerobr) * (TO_DAYS('
    $salida') - TO_DAYS( enero_inicio))ELSE NULL END) AS price11,

    (CASE WHEN ('
    $llegada' BETWEEN feb_inicio AND feb_fin and '$salida' BETWEEN feb_inicio AND feb_fin) 
    THEN sum(febbr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price12,
    (CASE WHEN ('
    $llegada' BETWEEN feb_inicio AND feb_fin and '$salida' > feb_fin) 
    THEN sum(febbr) * (TO_DAYS(marzo_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price13,
    (CASE WHEN ('
    $llegada' < feb_inicio and '$salida' BETWEEN feb_inicio AND feb_fin) 
    THEN sum(febbr) * (TO_DAYS('
    $salida') - TO_DAYS(feb_inicio))ELSE NULL END ) AS price14,

    (CASE WHEN ('
    $llegada' BETWEEN marzo_inicio AND marzo_fin and '$salida' BETWEEN marzo_inicio AND marzo_fin) 
    THEN sum(marzobr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price15,
    (CASE WHEN ('
    $llegada' BETWEEN marzo_inicio AND marzo_fin and '$salida' > marzo_fin) 
    THEN sum(marzobr) * (TO_DAYS(abril_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END ) AS price16,
    (CASE WHEN ('
    $llegada' < marzo_inicio and '$salida' BETWEEN marzo_inicio AND marzo_fin) 
    THEN sum(marzobr) * (TO_DAYS('
    $salida')  - TO_DAYS(marzo_inicio))ELSE NULL END ) AS price17,

    (CASE  WHEN ('
    $llegada' BETWEEN abril_inicio AND abril_fin and '$salida' BETWEEN abril_inicio AND abril_fin) 
    THEN sum(abrilbr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price21,
    (CASE WHEN ('
    $llegada' BETWEEN abril_inicio AND abril_fin and '$salida' > abril_fin) 
    THEN sum(abrilbr) * (TO_DAYS(mayo_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price22,
    (CASE WHEN ('
    $llegada' < abril_inicio and '$salida' BETWEEN abril_inicio AND abril_fin) 
    THEN sum(abrilbr) * (TO_DAYS('
    $salida')  - TO_DAYS(abril_inicio) )ELSE NULL END) AS price23,


    (CASE  WHEN ('
    $llegada' BETWEEN mayo_inicio AND mayo_fin and '$salida' BETWEEN mayo_inicio AND mayo_fin) 
    THEN sum(mayobr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price24,
    (CASE WHEN ('
    $llegada' BETWEEN mayo_inicio AND mayo_fin and '$salida' > mayo_fin) 
    THEN sum(mayobr) * (TO_DAYS(junio_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price25,
    (CASE WHEN ('
    $llegada' < mayo_inicio and '$salida' BETWEEN mayo_inicio AND mayo_fin) 
    THEN sum(mayobr) * (TO_DAYS('
    $salida')  - TO_DAYS(mayo_inicio) )ELSE NULL END) AS price26,

    (CASE  WHEN ('
    $llegada' BETWEEN junio_inicio AND junio_fin and '$salida' BETWEEN junio_inicio AND junio_fin) 
    THEN sum(juniobr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price27,
    (CASE WHEN ('
    $llegada' BETWEEN junio_inicio AND junio_fin and '$salida' > junio_fin) 
    THEN sum(juniobr) * (TO_DAYS(julio_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price28,
    (CASE WHEN ('
    $llegada' < junio_inicio and '$salida' BETWEEN junio_inicio AND junio_fin) 
    THEN sum(juniobr) * (TO_DAYS('
    $salida')  - TO_DAYS(junio_inicio) )ELSE NULL END) AS price29,

    (CASE  WHEN ('
    $llegada' BETWEEN julio_inicio AND julio_fin and '$salida' BETWEEN julio_inicio AND julio_fin) 
    THEN sum(juliobr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price30,
    (CASE WHEN ('
    $llegada' BETWEEN julio_inicio AND julio_fin and '$salida' > julio_fin) 
    THEN sum(juliobr) * (TO_DAYS(ago_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price31,
    (CASE WHEN ('
    $llegada' < julio_inicio and '$salida' BETWEEN julio_inicio AND julio_fin) 
    THEN sum(juliobr) * (TO_DAYS('
    $salida')  - TO_DAYS(julio_inicio) )ELSE NULL END) AS price32,

    (CASE  WHEN ('
    $llegada' BETWEEN ago_inicio AND ago_fin and '$salida' BETWEEN ago_inicio AND ago_fin) 
    THEN sum(agobr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price33,
    (CASE WHEN ('
    $llegada' BETWEEN ago_inicio AND ago_fin and '$salida' > ago_fin) 
    THEN sum(agobr) * (TO_DAYS(sep_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price34,
    (CASE WHEN ('
    $llegada' < ago_inicio and '$salida' BETWEEN ago_inicio AND ago_fin) 
    THEN sum(agobr) * (TO_DAYS('
    $salida')  - TO_DAYS(ago_inicio) )ELSE NULL END) AS price35,

    (CASE  WHEN ('
    $llegada' BETWEEN sep_inicio AND sep_fin and '$salida' BETWEEN sep_inicio AND sep_fin) 
    THEN sum(sepbr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price36,
    (CASE WHEN ('
    $llegada' BETWEEN sep_inicio AND sep_fin and '$salida' > sep_fin) 
    THEN sum(sepbr) * (TO_DAYS(oct_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price37,
    (CASE WHEN ('
    $llegada' < sep_inicio and '$salida' BETWEEN sep_inicio AND sep_fin) 
    THEN sum(sepbr) * (TO_DAYS('
    $salida')  - TO_DAYS(sep_inicio) )ELSE NULL END) AS price38,

    (CASE  WHEN ('
    $llegada' BETWEEN oct_inicio AND oct_fin and '$salida' BETWEEN oct_inicio AND oct_fin) 
    THEN sum(octbr) * (TO_DAYS('
    $salida') - TO_DAYS('$llegada'))ELSE NULL END) AS price39,
    (CASE WHEN ('
    $llegada' BETWEEN oct_inicio AND oct_fin and '$salida' > oct_fin) 
    THEN sum(octbr) * (TO_DAYS(nov_inicio) - TO_DAYS('
    $llegada'))ELSE NULL END) AS price40,
    (CASE WHEN ('
    $llegada' < oct_inicio and '$salida' BETWEEN oct_inicio AND oct_fin) 
    THEN sum(octbr) * (TO_DAYS('
    $salida')  - TO_DAYS(oct_inicio) )ELSE NULL END) AS price41,

    (CASE WHEN ('
    $llegada' < nov_inicio and '$salida' > nov_fin) 
    THEN sum(novbr) * (TO_DAYS(dec_inicio) - TO_DAYS( nov_inicio))ELSE NULL END) AS price42,

    (CASE WHEN ('
    $llegada' < dec_inicio and '$salida' > dec_fin) 
    THEN sum(decbr) * (TO_DAYS(nav_inicio) - TO_DAYS( dec_inicio))ELSE NULL END) AS price43,

    (CASE WHEN ('
    $llegada' < nav_inicio and '$salida' > nav_fin) 
    THEN sum(navbr) * (TO_DAYS(enero_inicio) - TO_DAYS( nav_inicio))ELSE NULL END) AS price44,

    (CASE WHEN ('
    $llegada' < enero_inicio and '$salida' > enero_fin) 
    THEN sum(enerobr) * (TO_DAYS(feb_inicio) - TO_DAYS(enero_inicio))ELSE NULL END) AS price45,

    (CASE WHEN ('
    $llegada' < feb_inicio and '$salida' > feb_fin) 
    THEN sum(febbr) * (TO_DAYS(marzo_inicio) - TO_DAYS(feb_inicio))ELSE NULL END) AS price46,

    (CASE WHEN ('
    $llegada' < marzo_inicio and '$salida' > marzo_fin) 
    THEN sum(marzobr) * (TO_DAYS(abril_inicio) - TO_DAYS(marzo_inicio))ELSE NULL END) AS price47,

    (CASE WHEN ('
    $llegada' < abril_inicio and '$salida' > abril_fin) 
    THEN sum(abrilbr) * (TO_DAYS(mayo_inicio) - TO_DAYS(abril_inicio))ELSE NULL END) AS price49,

    (CASE WHEN ('
    $llegada' < mayo_inicio and '$salida' > mayo_fin) 
    THEN sum(mayobr) * (TO_DAYS(junio_inicio) - TO_DAYS(mayo_inicio))ELSE NULL END) AS price50,

    (CASE WHEN ('
    $llegada' < junio_inicio and '$salida' > junio_fin) 
    THEN sum(juniobr) * (TO_DAYS(julio_inicio) - TO_DAYS(junio_inicio))ELSE NULL END) AS price51,

    (CASE WHEN ('
    $llegada' < julio_inicio and '$salida' > julio_fin) 
    THEN sum(juliobr) * (TO_DAYS(ago_inicio) - TO_DAYS(julio_inicio))ELSE NULL END) AS price52,

    (CASE WHEN ('
    $llegada' < ago_inicio and '$salida' > ago_fin) 
    THEN sum(agobr) * (TO_DAYS(sep_inicio) - TO_DAYS(ago_inicio))ELSE NULL END) AS price53,

    (CASE WHEN ('
    $llegada' < sep_inicio and '$salida' > sep_fin) 
    THEN sum(sepbr) * (TO_DAYS(oct_inicio) - TO_DAYS(sep_inicio))ELSE NULL END) AS price54,

    (CASE WHEN ('
    $llegada' < oct_inicio and '$salida' > oct_fin) 
    THEN sum(octbr) * (TO_DAYS(nov_inicio) - TO_DAYS(oct_inicio))ELSE NULL END) AS price55

    FROM precios where precios.id_propiedad = :propiedad
    "
    );
    $result->execute(array(
     
    'propiedad' => $propiedad
    )); 
    while (
    $row $result->fetch()){
    $price=$row["price"]; 
    $price1=$row["price1"];
    $price2=$row["price2"]; 
    $price3=$row["price3"]; 
    $price4=$row["price4"]; 
    $price5=$row["price5"]; 
    $price6=$row["price6"]; 
    $price7=$row["price7"]; 
    $price8=$row["price8"]; 
    $price9=$row["price9"]; 
    $price10=$row["price10"]; 
    $price11=$row["price11"]; 
    $price12=$row["price12"]; 
    $price13=$row["price13"]; 
    $price14=$row["price14"]; 
    $price15=$row["price15"]; 
    $price16=$row["price16"]; 
    $price17=$row["price17"]; 
    $price21=$row["price21"]; 
    $price22=$row["price22"]; 
    $price23=$row["price23"]; 
    $price24=$row["price24"]; 
    $price25=$row["price25"]; 
    $price26=$row["price26"]; 
    $price27=$row["price27"]; 
    $price28=$row["price28"];
    $price29=$row["price29"];
    $price30=$row["price30"]; 
    $price31=$row["price31"];
    $price32=$row["price32"];
    $price33=$row["price33"];
    $price34=$row["price34"];
    $price35=$row["price35"];
    $price36=$row["price36"];
    $price37=$row["price37"];
    $price38=$row["price38"];
    $price39=$row["price39"];
    $price40=$row["price40"];
    $price41=$row["price41"];
    $price42=$row["price42"];
    $price43=$row["price43"];
    $price44=$row["price44"];
    $price45=$row["price45"];
    $price46=$row["price46"];
    $price47=$row["price47"];
    $price49=$row["price49"];
    $price50=$row["price50"];
    $price51=$row["price51"];
    $price52=$row["price52"];
    $price53=$row["price53"];
    $price54=$row["price54"];
    $price55=$row["price55"];


    $total=$price+$price1+$price2+$price3+$price4+$price5+$price6+$price7+$price8+$price9+$price10+$price11+$price12+$price13+$price14+$price15+$price16+$price17+$price21+$price22+$price23+$price24+$price25+$price26+$price27
    +$price28+$price29+$price30+$price31+$price32+$price33+$price34+$price35+$price36+$price37+$price38+$price39+$price40+$price41+$price42+$price43+$price44+$price45+$price46+$price47+$price49+$price50+$price51+$price52+$price53+$price54+$price55;
    $half_round round(($total*2), 0)/2;
    $propiedad str_replace("_"" "$propiedad);
    $availability="$propiedad is available from $arrival_display to $departure_display.";
    $propiedad str_replace(" ""_"$propiedad);
    echo 
    "<p class=\"resulttext\">Available: $availability<br>Price in euros: $half_round<br>Nights: $dias</p>"
    echo 
    "<p>There is a booking arriving the same day as your
    departure date.</p>"
    ;
    ?><p>Total holiday cost for the <?php echo $dias?> nights: <?php print number_format($half_round2".""")?>€</p>
     <?php if ($percentage=="25"){
         
    $paynow = ($half_round) / 4;
         
    $balance = ($half_round) / 4*3;
         
    $whenpayment "8 weeks before arrival";
         
    ?><p>Deposit <?php  print number_format($paynow2"."""?>€ now (25%) and balance <?php print number_format($balance2".""")  ?>€ (75%) <?php echo $whenpayment;  ?>.</p>
    <?php  }
      if (
    $percentage=="50"){
         
    $paynow = ($half_round) / 2;
         
    $balance = ($half_round) / 2;
         
    $whenpayment "on arrival";
          
    ?><p>Deposit <?php  print number_format($paynow2"."""?>€ now (50%) and balance <?php print number_format($balance2".""")  ?>€ (50%) <?php echo $whenpayment;  ?>.</p>
    <?php
    }

    ?>
    <p>Deposit paypable either with credit/debit card using
    PayPal secure system (NO PayPal account required) or using your PayPal account.<br>
    Other forms of paypment only available for bookings by email.
    </p>
    <p>Company reserves the right to ask you to vacate the property at 10.00 on your departure date and that the time of arrival is no earlier than 14.00. This is in the case there are guests leaving or arriving on the same date. (please understand this is not always the case however we must prepare for the next client if the change is on the same day). 
    </p>
    <p>We do not pay any bank commissions, if you choose to use PayPals secure system or credit card there will be an increase of 4%, if you choose to book by email using bank transfer you pay the bank transfer cost.
    </p>
    <div class="textcenter">
    <form class="instant" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
    <input type="hidden" name="propiedad" value="<?php print $propiedad;?>">
    <input type="hidden" name="llegada" value="<?php print $llegada;?>">
    <input type="hidden" name="salida" value="<?php print $salida;?>">
    <input type="hidden" name="llegada2" value="<?php print $llegada;?>">
    <input type="hidden" name="salida2" value="<?php print $salida;?>">
    <input type="hidden" name="half_round" value="<?php print $half_round;?>">
    <input type="hidden" name="paynow" value="<?php print $paynow;?>">
    <input type="hidden" name="balance" value="<?php print $balance;?>">
    <input type="hidden" name="percentage" value="<?php print $percentage;?>">
    <input type="hidden" name="whenpayment" value="<?php print $whenpayment;?>">
    <input type="hidden" name="arrive" value="<?php print $arrival_display;?>">
    <input type="hidden" name="depart" value="<?php print $departure_display;?>">
    <input class="boton roundedcorner border" type="submit" value= "Proceed with booking using PayPal secure system" name="enviar3" alt="Instant payment"> </p>
    </form>
    <p>&nbsp;&nbsp;</p>
    <form action="https://www.marbellasunrentals.com/bookingenquirer.php" method="get" name="bookbuttons" id="bookbuttons">
            <input type="hidden" name="propiedad" value="<?php print $propiedad;?>"> 
    <p align="center"><input value="Book by email or enquirer" name="booking" type="submit" class="boton roundedcorner border" id="booking3"> </p>
    </form> 
    </div>
    <p>&nbsp;&nbsp;</p>

    <p>Check and calculate other dates:<br>(Different months can have different prices)</p>

    <?php
    }
    if (
    $dias<7)
    Last edited by newtonperri; February 11th, 2014 at 10:07 AM.
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    One last attempt before I give up:

    WHAT – IS – THE – RETURN – VALUE – OF – THE – EXECUTE() – CALL?

    You claim that the query “doesn't get executed”, which could mean pretty much anything. Now it's time to find out what really happens. The first step is to check the execute() call and see if it fails. But I can't do that if you refuse to give me this information.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    0
    Originally Posted by Jacques1
    One last attempt before I give up:

    WHAT – IS – THE – RETURN – VALUE – OF – THE – EXECUTE() – CALL?

    You claim that the query “doesn't get executed”, which could mean pretty much anything. Now it's time to find out what really happens. The first step is to check the execute() call and see if it fails. But I can't do that if you refuse to give me this information.
    Sorry, not sure how I can show the value of the execute call, suppose I dont understand what you mean, ever heard of execute value before, suppose you mean result.
    Below the query in english,
    as I said, it checks availability,
    if I insert for example 2014-02-11 as arrivaldate in the form, and 2014-02-21 as departure date, and there is no booking in the database, the script should just jump to the else and execute the next query, if there is a booking in the database between those dates, the script should stops there and gives an error message telling its not available.

    PHP Code:
    $query $dbh->prepare("SELECT DATE_FORMAT(arrival, '%e %b %Y') as lleg, DATE_FORMAT(departure, '%e %b %Y') a
    s sal, property, TO_DAYS(:departure) - TO_DAYS(:arrival) as days from bookings 
    where ( property = :property )
    AND ((:arrival2 BETWEEN arrival AND date_sub(departure, interval +1 day)) 
    or (:departure2 BETWEEN date_sub(arrival, interval -1 day) AND departure) or 
    (arrival <= :arrival3 AND departure >= :departure3) or (arrival >= :arrival4 AND departure <= :departure4))"
    );
    $query->execute(array(
     
    'departure' => $departure
         
    'arrival' => $arrival
       
    'property' => $property
        
    'arrival2' => $arrival
        
    'departure2' => $departure
        
    'arrival3' => $arrival
            
    'departure3' => $departure
        
    'arrival4' => $arrival
        
    'departure4' => $departure
        
    )); 

    As I said, the script is executed when javascript is disabled, but not when javascript is enabled.
    I.e means does not go to next query wich happens when javascript is enabled. Above query should give false.
    Last edited by newtonperri; February 11th, 2014 at 12:51 PM.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    78
    Rep Power
    0
    Originally Posted by Jacques1
    One last attempt before I give up:

    WHAT – IS – THE – RETURN – VALUE – OF – THE – EXECUTE() – CALL?

    You claim that the query “doesn't get executed”, which could mean pretty much anything. Now it's time to find out what really happens. The first step is to check the execute() call and see if it fails. But I can't do that if you refuse to give me this information.
    If I do this with javascript disabled the ok echo in the last else is printed on screen, however with javascript enabled the ok echo is not printed:

    PHP Code:
    $query $dbh->prepare("SELECT DATE_FORMAT(llegada, '%e %b %Y') as lleg, DATE_FORMAT(salida, '%e %b %Y') as sal,tiporeserva, propiedad, TO_DAYS(:salida) - TO_DAYS(:llegada) as dias from bookings where ( propiedad = :propiedad )
    AND ((:llegada2 BETWEEN llegada AND date_sub(salida, interval +1 day)) 
    or (:salida2 BETWEEN date_sub(llegada, interval -1 day) AND salida) or (llegada <= :llegada3 AND salida >= :salida3) or (llegada >= :llegada4 AND salida <= :salida4))"
    );
    $query->execute(array(
     
    ':salida' => $salida
         
    ':llegada' => $llegada
       
    ':propiedad' => $propiedad
        
    ':llegada2' => $llegada
        
    ':salida2' => $salida
        
    ':llegada3' => $llegada
            
    ':salida3' => $salida
        
    ':llegada4' => $llegada
        
    ':salida4' => $salida
        
    )); 
    $query->setFetchMode(PDO::FETCH_OBJ);
         if (
    $row $query->fetch()) {
           if (
    $row->tiporeserva=="larga"){ echo "<p>This property is available only for long term rentals, consult us for a price.</p>
    "
    ; } 
    else { 
    $propiedad str_replace("_"" "$propiedad); 
    echo 
    "<p>$propiedad is not available from $arrival_display to $departure_display.</p>"
    echo 
    "<p>$propiedad is occupied from "$row->lleg ." until "$row->sal ."</p>"
    }
     
    }
    //end check if available
    else{
        echo 
    "ok" 
    Printed on screen without javascript enabled:
    2014-02-192014-02-01Banana_Beach_1FEarray(6) { ["propiedad"]=> string(16) "Banana_Beach_1FE" ["day"]=> string(2) "01" ["month"]=> string(7) "2014-02" ["day2"]=> string(2) "19" ["month2"]=> string(7) "2014-02" ["enviar"]=> string(8) "Book now" } ok

    printed onscreen with javascript enabled:
    2014-02-192014-02-01Banana_Beach_1FEarray(6) { ["propiedad"]=> string(16) "Banana_Beach_1FE" ["enviar"]=> string(25) "[object HTMLInputElement]" ["day"]=> string(2) "01" ["day2"]=> string(2) "19" ["month"]=> string(7) "2014-02" ["month2"]=> string(7) "2014-02" }
    The ok in the else is not printed as if a parameter where missing
    Last edited by newtonperri; February 11th, 2014 at 01:06 PM.

IMN logo majestic logo threadwatch logo seochat tools logo