doulangchao8934 2015-07-19 16:47
浏览 66

如何同时将复选框值和文本字段数据发布到mysql数据库中

I need help posting data from HTML forms to a MySql database, especially checkboxes, I don't have a problem connecting to the database but I have a problem posting checkbox values and text field data at the same time, please assist me with the PHP code.

I have the following code.

<form action="action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
</fieldset>
<fieldset>
<legend>Course:</legend>
<input type="checkbox" name="french" value="French"> French
<br>
<input type="checkbox" name="german" value="German"> German 
<br>
<input type="checkbox" name="spanish" value="Spanish"> Spanish 
</fieldset>
<input type="submit" value="Submit">
</form>
  • 写回答

3条回答 默认 最新

  • douye2111 2015-07-19 16:58
    关注

    Post data are available in a global variable called $_POST.

    To get values from a HTML form, after submit you just have to use this variable.

    If for example french check-box is checked you will have:

    $_POST['french'] = "french"
    

    You have to see whether the user has checked that check-box or not. So just use isset() function:

    if (isset($_POST['french'])) {
        //french check-box is checked.
    } else {
        //french check-box is not checked.
    }
    

    And for text-fields you will have:

    $_POST['firstname'] = "Mickey"
    

    Also you have to change <form action="action_page.php"> to <form action="action_page.php" method="POST"> because HTML uses GET method by default.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化