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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧