Radio button post data of multiple input fields

前端 未结 4 865
半阙折子戏
半阙折子戏 2021-01-28 00:18

I have a form in my PHP page which is created by a loop through an array.

echo \'
4条回答
  •  后悔当初
    2021-01-28 00:42

    I solved the issue by doing the following.

    The guys above here all got me on the right track and couldn't have done it without them!

    Changed

    
    
    

    To

    
    
    

    Also changed

    if (isset($_POST['add_to_chart']))
    {
        $product_id = $_POST['product_id'];
        $size = $_POST['size'][0];
        $qty = $_POST['amount'];
    }
    

    To this

    if (isset($_POST['add_to_chart']))
    {
        // Array ID key
        $key = key($_POST['size']);
    
        $product_id = $_POST['product_id'];
        $size = $_POST['size'][$key];
        $qty = $_POST['amount'][$key];
    }
    

    Works like a charm! Thank you all for your very helpful comments!

提交回复
热议问题