<?php

include('../../conf/conn.php');

function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

$query = "select * from coupon where code = '" . mysqlSecurity($conn, $_GET["code"]) . "' and `status` != 'delete';";
$result = mysqli_query($conn, $query);
if ($result->num_rows < 0) {
    die();
}
$row = mysqli_fetch_assoc($result);

if ($row["start_date"] <= date("Y-m-d") && $row["end_date"] > date("Y-m-d")) {
    echo json_encode(["discount_rate" => $row["discount_rate"],
        "en_name" => $row['coupon_name'],
        "zh_name" => $row['zh_coupon_name']]);
}
