PHP和MySQL - 发送复选框,单选按钮,然后从用户菜单结果下降到mysql数据库,并将其存储

2019-11-01 22:48发布

我想有存储在MySQL数据库中我的表单数据。 我想用户键入或点击到存储在那里的一切。 我能够有存储在MySQL的成功我的文本字段。 我有麻烦搞清楚如何发送多个复选框,单选按钮和列表下拉到MySQL,并将它存储在那里。 我甚至不知道从哪里开始。 请帮忙。

CREATE TABLE wer(
ID int NOT NULL auto_increment,
student_gender varchar(6),
student_session_one_preference varchar(30),
student_session_two_preference varchar(30),
waldron_scholarship tinyint,
jesse_van_anterp_huyck_scholarship tinyint,
edward_raney_scholarship tinyint,
school_type varchar(25),
student_statemenet_consent_check_box tinyint,
guardian_statemenet_consent_check_box tinyint,
waiver tinyint, 
PRIMARY KEY(ID)
);



$student_gender = trim(mysql_prep($_POST['student_gender']));
$student_session_one_preference = trim(mysql_prep($_POST['student_session_one_preference']));
$student_session_two_preference = trim(mysql_prep($_POST['student_session_two_preference']));
$waldron_scholarship = trim(mysql_prep($_POST['waldron_scholarship']));
$jesse_van_anterp_huyck_scholarship = trim(mysql_prep($_POST['jesse_van_anterp_huyck_scholarship']));   
$edward_raney_scholarship = trim(mysql_prep($_POST['edward_raney_scholarship']));
$school_type = trim(mysql_prep($_POST['school_type']));
$student_statement_consent_check_box = trim(mysql_prep($_POST['student_statement_consent_check_box']));
$guardian_statement_consent_check_box = trim(mysql_prep($_POST['guardian_statement_consent_check_box']));
$waiver = trim(mysql_prep($_POST['waiver']));



<input type="radio" name="student_gender" value="Male">Male<br>
<input type="radio" name="student_gender" value="Female">Female<br>
<select name="student_session_one_preference">
<option value="Session 1">Session 1: June 30 - July 21</option>
<option value="Session 2">Session 2: July 28 - August 18</option>
</select> <br/>

Preference 2:
<select name="student_session_two_preference">
<option value="Session 1">Session 1: June 30 - July 21</option>
<option value="Session 2">Session 2: July 28 - August 18</option>
</select>
<input type="checkbox" name="waldron_scholarship" value="Waldron Scholarship">Waldron Scholarship<br/>
<input type="checkbox" name="jesse_van_anterp_huyck_scholarship" value="Jesse Van Anterp Huyck Scholarship">Jesse Van Anterp Huyck Scholarship<br/>
<input type="checkbox" name="edward_raney_scholarship" value="Edward Raney Scholarship">Edward Raney Scholarship<br/>


<select name="school_type">
<option value="Public">Public</option>
<option value="Private">Private Parochial</option>
<option value="Other">Other</option>
</select>


<input type="radio" name="waiver" value="">I waive any right of access that I may have to information submitted by my referee<br>
<input type="radio" name="waiver" value="">I do not waive any right of access that I may have to information submitted by my referee<br>


<input type="checkbox" name="student_statement_consent_check_box" value="Agree">By checking this box, the student acknowledges <br/> that they have read the statement <br/> of consent and agrees with it.<br>


<input type="checkbox" name="guardian_statement_consent_check_box" value="Agree">By checking this box, the guardian acknowledges <br/> that they have read the statement <br/> of consent and agrees with it.<br>

Answer 1:

你可以试试这个代码

<?php
    if(!empty($_POST) && isset($_POST["submit-btn"])){
        $gender = isset($_POST["student_gender"]) ? $_POST["student_gender"] : "";
        $student_session_one_preference = isset($_POST["student_session_one_preference"]) ? $_POST["student_session_one_preference"] : "";
        // do the rest of the elements

        echo $student_session_one_preference;
    }
?>


<form method="POSt">
<input type="radio" name="student_gender" value="Male">Male<br>
<input type="radio" name="student_gender" value="Female">Female<br>


<select name="student_session_one_preference">
                    <option value="Session 1">Session 1: June 30 - July 21</option>
                    <option value="Session 2">Session 2: July 28 - August 18</option>
                </select> <br/>
                Preference 2:
                <select name="student_session_two_preference">
                    <option value="Session 1">Session 1: June 30 - July 21</option>
                    <option value="Session 2">Session 2: July 28 - August 18</option>
                </select>


<input type="checkbox" name="waldron_scholarship" value="Waldron Scholarship">Waldron Scholarship<br/>
                    <input type="checkbox" name="jesse_van_anterp_huyck_scholarship" value="Jesse Van Anterp Huyck Scholarship">Jesse Van Anterp Huyck Scholarship<br/>
                    <input type="checkbox" name="edward_raney_scholarship" value="Edward Raney Scholarship">Edward Raney Scholarship<br/>


<select name="school_type">
                    <option value="Public">Public</option>
                    <option value="Private">Private Parochial</option>
                    <option value="Other">Other</option>
                </select>


<input type="radio" name="waiver" value="">I waive any right of access that I may have to information submitted by my referee<br>
                    <input type="radio" name="waiver" value="">I do not waive any right of access that I may have to information submitted by my referee<br>


<input type="checkbox" name="student_statement_consent_check_box" value="Agree">By checking this box, the student acknowledges <br/> that they have read the statement <br/> of consent and agrees with it.<br>


<input type="checkbox" name="guardian_statement_consent_check_box" value="Agree">By checking this box, the guardian acknowledges <br/> that they have read the statement <br/> of consent and agrees with it.<br>

<input type="submit" value="Submit" name="submit-btn">

</form>

此代码假定表单提交到同一页面。

希望这可以帮助你。



文章来源: php and mysql - Send checkbox, radio button, and drop down menu results from user to mysql database and store it there