<?php

$payload = file_get_contents("php://input");

if (ISSET($payload))
{
    $data = json_decode($payload, true);
    $url        = $data['url'];
    $helpful    = $data['helpful'];
    $comment    = $data['text'];
    $output = $helpful;
    // $url = mysql_real_escape_string($data['url']);
    // $txt = mysql_real_escape_string($data['text']);
    
    $servername = "localhost";
    // Lower environments
    // $username = "id-webhelpsearch";
    // $password = "OHnCJiTa526nUVrQ";
    // Production
    $username = "wthProd";
    $password = "00slcEsVTVMY";
    $dbname = "wasthishelpful";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    $sql = "INSERT INTO wth1 (url, helpful, comment) 
                 VALUES('" . $url . "',' $helpful','" . $comment . "')";
    
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    
    $conn->close();
    
}


?>
