Cannot insert data in the database using option(textarea)

前端 未结 2 411
温柔的废话
温柔的废话 2021-01-29 15:13

I got this code but it is not inserting the content of the option (textarea) into the database.

connection.php



        
2条回答
  •  悲哀的现实
    2021-01-29 15:31

    You need to name the

    Then if you want the value to be 0 or 1, depending on selected or not, you can use the following to replace this:

    $foodA = $_POST['foodA'];
    $foodB = $_POST['foodB'];
    $foodC = $_POST['foodC'];
    $foodD = $_POST['foodD'];
    $foodE = $_POST['foodE'];
    

    to

    $foodA = 0;
    $foodB = 0;
    $foodC = 0;
    $foodD = 0;
    $foodE = 0;
    
    foreach ($_POST['food'] as $value) {
        if($value == 'foodA')
            $foodA = 1;
        if($value == 'foodB')
            $foodB = 1;
        if($value == 'foodC')
            $foodC = 1;
        if($value == 'foodD')
            $foodD = 1;
        if($value == 'foodE')
            $foodE = 1;
    }
    

提交回复
热议问题