v2.5.2
Giriş yap

Post edilirken array olarak kayıt ediyor

resat
342 defa görüntülendi

Merhaba arkadaşlar, verileri post ettikten sonra INSERT INTO order_products $unit ve $date array olarak kayıt ediliyor. Posttan gelen verileri alamıyorum. Nerede hata yapıyorum acaba

   include "_inc/dbConnect.php";
header('Content-type: application/json');
if (isset($_POST['getproducts_fromsupplier'])){
    $data = $db->prepare('SELECT * FROM products where product_supplier=?');
    $data->execute([$_POST["suplier_id"]]);
    echo json_encode($data->fetchAll(PDO::FETCH_ASSOC));
    die();
}
if (isset($_POST['make_order'])){
    $note =$_POST["note"];
    $price = 0;
    $order_number="MZR".rand(0,999999);
    foreach (explode(',',$_POST["prices"]) as $item) {
        $price+=(int)$item;
    }



    $data = $db->prepare('INSERT INTO  orders SET note=?,supplier_id=?,order_number=?,price=?');
    $data->execute([$note,$_POST["supplier_id"],$order_number,$price]);

    foreach (explode(',',$_POST["products"]) as $item) {

        $product=$db->prepare("SELECT * FROM products WHERE id=?");
        $product->execute([$item]);
        $product=$product->fetch(PDO::FETCH_ASSOC);

        
        $unit=explode(',',$_POST["units"]);
        $date=explode(',',$_POST["dates"]);

        $order_product=$db->prepare("INSERT INTO order_products SET product_name=?,product_price=?,product_unit=?,product_date=?,product_color=?,product_id=?,order_number=?");
        $order_product->execute([$product["product_name"],$product["product_price"],$unit,$date,$product["product_color"],$product["id"],$order_number]);

    }
    if($data){
        echo json_encode(['success'=>true]);
    }
    die();
}
Cevap yaz
Cevaplar (1)
webdevyusuf
704 gün önce

Merhaba, formun HTML kodunu ve yukarıda verilen kodun bulunduğu sayfaya aşağıda bırakacağım kodu yazıp çıktıyı iletebilir misiniz?

print_r($_POST);
exit;