<?php

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

if (ISSET($payload))
{
    $data = json_decode($payload, true);
    console.log(JSON.stringify(data));
    $url        = $data['url'];
    $name    = $data['name'];
    $custnum    = $data['custnum'];
    // $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 = "livechat";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    $sql = "INSERT INTO livechat (url, name, custnum) 
                 VALUES('" . $url . "',' $name','" . $custnum . "')";
    
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    
    $conn->close();
    
}


?>
