html - How to use index of loop in Post method PHP -
i need help! trying save variable in sql table using php have problem. there 2 questions in php, first concern continent , second depended continent. want use loop check of continents has been selected in first question , save value of second question. hide option of unchecked continent using javascript code (i don't have problem).
the html code:
<form method="post" action=""> <fieldset><legend>continents</legend> <select id="q1" name="q1"> <option value="1">africa</option> <option value="2">asia</option> <option value="3">australia</option> <option value="4">america</option> <option value="5">europe</option> </select> <select id="q2" name="africa"> <option value="1">choice 1</option> <option value="2">choice 2</option> </select> <select id="q2" name="asia"> <option value="1">choice 1</option> <option value="2">choice 2</option> </select> <select id="q2" name="australia"> <option value="1">choice 1</option> <option value="2">choice 2</option> </select> <select id="q2" name="america"> <option value="1">choice 1</option> <option value="2">choice 2</option> </select> <select id="q2" name="europe"> <option value="1">choice 1</option> <option value="2">choice 2</option> </select> </fieldset>
the php code
$q1 = $_post['q1']; $continents = array("africa","asia", "australia","america","europe"); ($i = 1; $i <= 5; $i++) { if($q1 == $i) { $q2 = $_post[$continents[$i-1]] } }
your array should 1 5
instead of 0 4
have values 1 5
in q1
.
alternatively, suggest change html structure continent value in single line without using loop. need change values of continent like,
<select id="q1" name="q1"> <option value="africa">africa</option> <option value="asia">asia</option> <option value="australia">australia</option> <option value="america">america</option> <option value="europe">europe</option> </select>
and value of selected continent use $_post[$_post['q1']]
. egs, $_post['q1']=asia
, $_post['asia']
return asia's choice,
$q2= $_post[$_post['q1']];
Comments
Post a Comment