dsa99349 2016-04-14 07:11
浏览 86
已采纳

无法从HTML表单复选框中获取值以插入MySQL数据库列

I am new to this website and just want to say thank you in advance for any assistance. So, I have a form that's linked to a separate PHP script, and everything else on the form inserts into the database just fine except for the check boxes. The current code I have below received the "Undefined index:" error and I have tried following many tutorials but this is as far as I've gotten thus far.

Here is my HTML code for the checkboxes:

<input type="checkbox" name="problem_list[]" value="Handle Bars">Handle Bars<br>
        <input type="checkbox" name="problem_list[]" value="Frame">Frame<br>
        <input type="checkbox" name="problem_list[]" value="Pedals">Pedals<br>
        <input type="checkbox" name="problem_list[]" value="Chain">Chain<br>
        <input type="checkbox" name="problem_list[]" value="Brakes">Brakes<br>
        <input type="checkbox" name="problem_list[]" value="Gears">Gears<br>
        <input type="checkbox" name="problem_list[]" value="Tires">Tires<br>

And here is my PHP code for related to the checkboxes:

$problem_list = ""; // declare problem_list
if (isset($_POST["problem_list"])) 
{$problem_list = implode(" ,",$_POST['problem_list']);
}
$sql = "INSERT INTO bike_repairs (employee_id, date, first_name, last_name, phone, email, make, model, color, overall_problem_area, specific_issue) 
VALUES ('$value16', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '".$problem_list."', '$value14')";

Just to recap, the form works, the database connection is established, all other form elements are accounted for in variables and inserting just fine. So this is the last thing I need to figure out. Thanks again for any assistance!

  • 写回答

3条回答 默认 最新

  • douqianbiao4216 2016-04-14 07:29
    关注

    if you edit like this, what you got ?

    if ( !empty($_POST["problem_list"]) ) 
    {
        $problem_list = implode(" ,",$_POST['problem_list']);
        $sql = "INSERT INTO bike_repairs (employee_id, date, first_name, last_name, phone, email, make, model, color, overall_problem_area, specific_issue) 
        VALUES ('$value16', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '".$problem_list."', '$value14')";
    }
    else echo 'problem_list is empty';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程