dongzhabo2796 2017-07-20 22:00
浏览 55
已采纳

使用PHP将多个选择表单中的数据存储到MYSQL

I am looking for help on storing data from multiple select form to MYSQL using PHP, here is my form

            <form action="" method="post">

            Choose your preferred browser
            <select name="browsers"> 
            <option value="Internet Explorer">
            <option value="Firefox">
            <option value="Chrome">
            <option value="Opera">
            <option value="Safari">
            </select>

            Choose your preferred car
            <select name="carlist">
            <option value="volvo">Volvo</option>
            <option value="saab">Saab</option>
            <option value="opel">Opel</option>
            <option value="audi">Audi</option>
            </select>

            <input type="submit">
            </form> 
  • 写回答

1条回答 默认 最新

  • doulu3808 2017-07-20 22:11
    关注

    $_POST['browser']; and $_POST['carlist']; each hold their own different value. So you can easily fetch each of their values.

    $car = $_POST['carlist'];
    $browser = $_POST['browser'];
    

    Now it's just a matter of question where you wanna take it from there. F.ex. if you'd like to save it to a database;

    // Just make it a standard to secure your database inputs
    $car = mysqli_real_escape_string($conn, $_POST['carlist']);
    $browser = mysqli_real_escape_string($conn, $_POST['browser']);
    
    $sql = "INSERT INTO someTable (car, browser) VALUES ('".$car."', '".$browser."')";
    mysqli_query($conn, $sql);
    

    This is very simplified of course, but I hope it gives you an idea.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 echarts图表制作