<?php

if (isset($_POST)) {
    // sanitize data  
    $sendername = htmlentities($_POST['sendername'], ENT_QUOTES); 
    $senderemail = htmlentities($_POST['senderemail'], ENT_QUOTES);
    $sendercontact = htmlentities($_POST['sendercontact'], ENT_QUOTES);
    $senderaddress = htmlentities($_POST['senderaddress'], ENT_QUOTES);
    $dispatchlocation = htmlentities($_POST['dispatchlocation'], ENT_QUOTES);
    $receivername = htmlentities($_POST['receivername'], ENT_QUOTES);
    $receivercontact = htmlentities($_POST['receivercontact'], ENT_QUOTES);
    $receiveremail = htmlentities($_POST['receiveremail'], ENT_QUOTES);
    $receiveraddress = htmlentities($_POST['receiveraddress'], ENT_QUOTES);
    $ftype = htmlentities($_POST['ftype'], ENT_QUOTES);
    $edd = htmlentities($_POST['edd'], ENT_QUOTES);
       
    // store data to the database
    try {
        $dbh = new PDO("mysql:host=localhost;dbname=unithsen_unitcargologistics", "unithsen_root", "K24V=(}+8C}k");
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        // prepare code 
        $sth = $dbh->prepare("INSERT INTO client_details (id, sendername, senderemail, sendercontact, senderaddress, dispatchlocation, receivername, receivercontact, receiveremail, receiveraddress, ftype, edd)
            VALUES (NULL, :sdn, :sde, :sdc, :sda, :dpl, :rcn, :rcc, :rce, :rca, :ft, :ed);");

        $sth->bindValue(":sdn", $sendername);
        $sth->bindValue(":sde", $senderemail);
        $sth->bindValue(":sdc", $sendercontact);
        $sth->bindValue(":sda", $senderaddress);
        $sth->bindValue(":dpl", $dispatchlocation);
        $sth->bindValue(":rcn", $receivername);
        $sth->bindValue(":rcc", $receivercontact);
        $sth->bindValue(":rce", $receiveremail);
        $sth->bindValue(":rca", $receiveraddress);
        $sth->bindValue(":ft", $ftype);
        $sth->bindValue(":ed",  $edd);

        $sth->execute();

        // Additional code if the insertion is successful
        echo "Data successfully inserted!";
    } catch (PDOException $e) {
        echo "Error: " . $e->getMessage();
    }
}
?>