<?php

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

if (ISSET($payload))
{
    $data = json_decode($payload, true);

    $var1    = $data['url'];
    $var2    = $data['text'];
    // $var1 = mysqli::escape_string($data['url']);
    // $var2 = mysqli::escape_string($data['text']);
    
    $servername = "localhost";
    $username = "id-webhelpsearch";
    $password = "OHnCJiTa526nUVrQ";
    $dbname = "webhelp";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    // Prepare and bind
    $stmt = $conn->prepare("INSERT INTO tb_webhelpsearch (url, searchText) VALUES (?, ?)");
    $stmt->bind_param("ss",$url, $txt);

    // set parameters and execute
    $url = $var1;
    $txt = $var2;
    $stmt->execute();
    
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $stmt->close();

    $conn->close();
    
}


?>
