<?php
include 'conn.php';
//Select data from database

include 'funciones.php';

session_start();
$_SESSION['database'] = $_GET['database'];
$_SESSION['numero'] = $_GET['numero'];
$_SESSION['monto'] = $_GET['monto'];

$_SESSION['gift_number'] = "";

$hoynow = getdate();

if ($_SESSION['monto'] == "") {
    $_SESSION['monto'] = "0";

}

$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"];

logs($timeStamp);

$montoesql = "select gift_certificate.gift_number FROM " . $_SESSION['database'] . ".gift_certificate where gift_certificate.gift_number='" . $_SESSION['numero'] . "' ";

logs($montoesql);

$qur = $connection->query($montoesql);

while ($r = mysqli_fetch_assoc($qur)) {

    $_SESSION['gift_number'] = $r['gift_number'];
}

if ($_SESSION['gift_number'] == "0") {
    echo "false";

} else {

    $SQLupdate = "update " . $_SESSION['database'] . ".gift_certificate set gift_fechault='" . $timeStamp . "',gift_monto=0 where gift_certificate.gift_number='" . $_SESSION['numero'] . "' limit 1 ";

    logs($SQLupdate);

    if ($connection->query($SQLupdate) === true) {
        echo "true";
    } else {
        echo "Error: " . $SQLupdate . "<br>" . $conn->error;
    }

}

@mysqli_close($connection);
?>