php - passing values to sql through check boxes and dropdowns -
how can pass drop down values sql database , check box example if user selects english , maths value inserted in database 1 or else value 0
<form> <p id="p1">select year</p> <select id="year_sel"> <option value="blank"></option> <option id="primary" value="primary">primary</option> <option value="1">year one</option> <option value="2">year two</option> <option value="3">year three</option> </select> <input type="checkbox" name="math" value="math">math<br> <input type="checkbox" name="english" value="english">english<br> <input type="checkbox" name="healthscience" value="healthscience">health science<br> <input class="sub_reg" type="submit" value="register subjects" /> </form>
first, <select id="year_sel"> needs name attribute post ->
<select id="year_sel" name="year_sel" > since using <form> default get, selected value in $_get
$year_sel = $_get['year_sel']; if changed
<form method="post"> then in $_post
$year_sel = $_post['year_sel'] second, checkboxes posted if checked, can use isset() set value using ternary -
$math = isset($_get['math']) ? 1 : 0; $english = isset($_get['english']) ? 1 : 0; ...[rest of checkboxes]... swap $_get/$_post select
$math = isset($_post['math']) ? 1 : 0; $english = isset($_post['english']) ? 1 : 0; 
Comments
Post a Comment