<?php

//machine_action.php

include "../connection.php";

session_start();

$output = '';

if (isset($_POST["action"])) {

    // Fetch machines
    if ($_POST["action"] == "machine_fetch") {

        $draw = $_POST['draw'];
        $row = $_POST['start'];
        $rowperpage = $_POST['length'];
        $columnIndex = $_POST['order'][0]['column'];
        $columnName = $_POST['columns'][$columnIndex]['data'];
        $columnSortOrder = $_POST['order'][0]['dir'];
        $searchValue = $_POST['search']['value'];

        $searchQuery = " ";
        if ($searchValue != '') {
            $searchQuery = " and (id LIKE '%" . $searchValue . "%'
                                OR ssh_host LIKE '%" . $searchValue . "%'
                                OR ssh_username LIKE '%" . $searchValue . "%'
                                OR ssh_password LIKE '%" . $searchValue . "%'
                                OR ssh_port LIKE '%" . $searchValue . "%' ) ";
        }

        $sqlMachine = mysqli_query($conn, "SELECT count(*) AS allcount FROM tbl_machines");
        $records = mysqli_fetch_assoc($sqlMachine);
        $totalRecords = $records['allcount'];

        $sqlMachine = mysqli_query($conn, "SELECT count(*) AS allcount FROM tbl_machines WHERE 1 " . $searchQuery);
        $records = mysqli_fetch_assoc($sqlMachine);
        $totalRecordwithFilter = $records['allcount'];

        $machineQuery = "SELECT * FROM tbl_machines WHERE 1 " . $searchQuery . " ORDER BY " . $columnName . " " . $columnSortOrder . " LIMIT " . $row . "," . $rowperpage;

        $machinesRecords = mysqli_query($conn, $machineQuery);
        $data = array();

        while ($row = mysqli_fetch_assoc($machinesRecords)) {

            $data[] = array(
                "id"              =>  $row['id'],
                "ssh_host"        =>  $row['ssh_host'],
                "ssh_username"    =>  $row['ssh_username'],
                "ssh_password"    =>  $row['ssh_password'],
                "ssh_port"        =>  $row['ssh_port'],
                "update"          =>  '<button type="button" class="btn btn-danger update_machine" id="' . $row['id'] . '"><i class="fas fa-edit"></i></button>'
            );
        }

        $response = array(
            "draw"                  => intval($draw),
            "iTotalRecords"         => $totalRecords,
            "iTotalDisplayRecords"  => $totalRecordwithFilter,
            "aaData"                => $data
        );

        echo json_encode($response);
    }

    // Register Machine
    if ($_POST["action"] == "create_machine") {

        $ssh_host = $_POST['ssh_host'];
        $ssh_username = $_POST['ssh_username'];
        $ssh_password = $_POST['ssh_password'];
        $ssh_port = $_POST['ssh_port'];

        // Check if ssh_username already exists.
        $sql = "SELECT * FROM tbl_machines WHERE ssh_username = '$ssh_username'";
        $result = mysqli_query($conn, $sql);
        $checkrows = mysqli_num_rows($result);

        if ($checkrows > 0) {
            $output = array(
                'status'    =>  'error',
                'error'     =>  'SSH Username already exists.'
            );
        } else {
            $sql = "INSERT INTO tbl_machines (ssh_host, 
                                        ssh_username, 
                                        ssh_password,
                                        ssh_port) 
                                VALUES('$ssh_host', 
                                    '$ssh_username',
                                    '$ssh_password',
                                    '$ssh_port')";
            if (mysqli_query($conn, $sql)) {
                $output = array(
                    'status'    => 'success',
                    'success'   =>  'New machine successfully created.'
                );
            } else {
                $output = array(
                    'status'    =>  'error',
                    'error'     =>  'Error creating machine.'
                );
            }
        }

        echo json_encode($output);
    }

    // Rest of your existing code...
}
?>
şimdi bu machine_action.php
alttakide machine.php
<?php include('include/header.php'); ?>

<div class="container">
    <!-- Machines DataTable -->
    <div class="card mb-3" style="margin-top:30px">
        <div class="card-header">
            <div class="row">
                <div class="col-md-9 font-weight-bold"><i class="fas fa-users"></i> Machine List</div>
                <div class="col-md-3" align="right">
                    <button type="button" id="add_button" class="btn btn-primary btn-sm">Add New Machine</button>
                </div>
            </div>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <span id="success_message"></span>
                <table class="table table-bordered" id="machinetable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>SSH Host</th>
                            <th>SSH Username</th>
                            <th>SSH Password</th>
                            <th>SSH Port</th>
                            <th>Update</th>
                        </tr>
                    </thead>
                    <tfoot>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
    <!-- End Machines DataTable -->

    <!-- Machine Modal -->
    <div class="modal fade" id="formModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="modal_title"></h4>
                    <button class="close" data-dismiss="modal">
                        <span>&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="machine_form">
                        <div id="alert_error_message" class="alert alert-danger collapse" role="alert">
                            Please check in on some of the fields below.
                        </div>
                        <div class="mb-3">
                            <label for="ssh_host">SSH Host <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="ssh_host" name="ssh_host"
                                placeholder="Enter SSH Host">
                            <div id="ssh_host_error_message" class="text-danger"></div>
                        </div>
                        <div class="mb-3">
                            <label for="ssh_username">SSH Username <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="ssh_username" name="ssh_username"
                                placeholder="Enter SSH Username">
                            <div id="ssh_username_error_message" class="text-danger"></div>
                        </div>
                        <div class="mb-3">
                            <label for="ssh_password">SSH Password <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" id="ssh_password" name="ssh_password"
                                placeholder="Enter SSH Password">
                            <div id="ssh_password_error_message" class="text-danger"></div>
                        </div>
                        <div class="mb-3">
                            <label for="ssh_port">SSH Port <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="ssh_port" name="ssh_port"
                                placeholder="Enter SSH Port">
                            <div id="ssh_port_error_message" class="text-danger"></div>
                        </div>
                        <hr class="mb-4">
                        <div class="modal-footer">
                            <input type="hidden" name="machine_id" id="machine_id" />
                            <input type="hidden" name="action" id="action" value="Add" />
                            <input type="submit" name="button_action" id="button_action" class="btn btn-primary"
                                value="Add" />
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- End Machine Modal -->
</div>

<?php include('include/footer.php'); ?>

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

<!-- DataTables CSS and JS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>

<!-- Bootstrap CSS and JS (Optional, if not already included) -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<!-- DataTable Initialization Script -->
<script>
    $(document).ready(function () {
        var datatable = $('#machinetable').DataTable({
            'processing': true,
            'serverSide': true,
            'ajax': {
                url: 'machine_action.php',
                type: 'POST',
                data: {
                    action: 'machine_fetch'
                }
            },
            'columns': [
                { data: 'id' },
                { data: 'ssh_host' },
                { data: 'ssh_username' },
                { data: 'ssh_password' },
                { data: 'ssh_port' },
                { data: 'update_button' } // Add a column for update button
            ]
        });

        $('#add_button').click(function () {
            $('#machine_form')[0].reset();
            $('.modal-title').text('Add New Machine');
            $('#action').val('Add');
            $('#button_action').val('Add');
            $('#formModal').modal('show');
        });

        $('#machine_form').on('submit', function (event) {
            event.preventDefault(); // Prevent the default form submission

            var formData = $(this).serialize();

            $.ajax({
                url: 'machine_action.php',
                method: 'POST',
                data: formData,
                dataType: 'json',
                success: function (data) {
                    if (data.status === 'success') {
                        $('#formModal').modal('hide');
                        datatable.ajax.reload(); // Reload the DataTable after successful submission
                        // You can also display a success message if needed
                    } else {
                        // Handle errors or display error messages
                        // You can use data.error to get the error message from the server
                        console.error('Error:', data.error);
                    }
                }
            });
        });
    });
</script>
bu kodlar sağlam çalışıyor ama add new machine ve add butonu çalışmıyor databasem tbl_machines içinde id ssh_host ssh_username ssh_password üçüde varchar 255 ssh_port var birde buda int 4 nasıl çalıştırabilirim ?