0

次のコードがあります。

Index.php <SCRIPT>
$("#insert").click(function(e) {
                                
                                $.ajax({
                                    url: ["./required/orderaction.php"],
                                    type: "POST",
                                    data: $("#add-form-data").serialize() + "&action=insert",
                                    success: function(response) {
                                        console.log(amodate);
                                        Swal.fire({
                                            title: 'Order added successfully!',
                                            showConfirmButton: false,
                                            type: 'success',
                                            icon: 'success',
                                            timer: 500,
                                            timerProgressBar: true,
                                        })

                                        $("#addOrderModal").modal("hide");
                                        
                                        ShowAllOrders();

                                    }
                                });
                        });

orderaction.php
if (isset($_POST['action']) && $_POST['action'] == "insert") {
        $odate = $_POST['amodate'];
        $oclient = $_POST['amoclient'];
        $ocode = $_POST['amoprojectcodes'];
        $oname = $_POST['amoprojectname'];
        $otype = $_POST['amotype'];
        $oamount = $_POST['amoamount'];

        $db->insert($odate, $oclient, $ocode, $oname, $otype, $oamount);
    }

db.php
// private $dsn = "sqlsrv:Server=localhost;Database=test";    // Conect with SQLServer
    private $dsn = "mysql:host=localhost;dbname=limardfeng";   // Conect with MySQL
    private $username = "root";
    private $pass = "";
    public $conn;

    public function __construct()
    {
        try {
            $this->conn = new PDO($this->dsn, $this->username, $this->pass);
            // echo "Succesfully Conected!";
        } catch (PDOException $e) {
            echo $e->getMessage();
        }
    }

public function insert($odate, $oclient, $ocode, $oname, $otype, $oamount)
    {
        $sql = "INSERT INTO tbl_order (odate, oclient, ocode, oname, otype, oamount) VALUES (:amodate,:amoclient,:amoprojectcodes,:amoprojectname,:amotype,:amoamount)";
        $stmt = $this->conn->prepare($sql);
        $stmt->execute(['amodate' => $odate, 'amoclient' => $oclient, 'amoprojectcodes' => $ocode, 'amoprojectname' => $oname, 'amotype' => $otype, 'amoamount' => $oamount]);
        return true;       
    }

私は上記と同様のコードを持っていますが、これは機能しません。スクリプト コードは、「console.log("Works");」を追加するとインスペクションで機能することを示しています。それ以外は私は困惑しています。助けてください。

4

0 に答える 0