dsp77 Posted March 25, 2010 Share Posted March 25, 2010 Hello, I have a quiz to make with approximate 500 input boxes that i need to record in the data base, i am able to make them i use $question1=$_POST['question1']; $query="INSERT INTO quiz question1 VALUES $question1; etc. but there are to many i'm sure that is a better way not to write so many lines. Please guide me finding a better practice. Quote Link to comment Share on other sites More sharing options...
ignace Posted March 25, 2010 Share Posted March 25, 2010 Sure there is but you need to give us something more to work with like where come these questions and answers from? Quote Link to comment Share on other sites More sharing options...
dsp77 Posted March 25, 2010 Author Share Posted March 25, 2010 i have only tables like this <table id="tabela1" cellspacing="0" cellpadding="0"> <tr> <td align="center"><strong>Date</strong></td> <td align="center"><strong>Anul universitar 2004/2005</strong></td> <td align="center"><strong>Anul universitar 2008/2009</strong></td> </tr> <tr> <td>a. nume şi prenume</td> <td align="center"><input name="3_an0405_a" type="checkbox" id="3_an0405_a" value="1" /></td> <td align="center"><input name="3_an0809_a" type="checkbox" id="3_an0809_a" value="1" /></td> </tr> <tr> <td>b. sex </p></td> <td align="center"><input name="3_an0405_b" type="checkbox" id="3_an0405_b" value="1" /></td> <td align="center"><input name="3_an0809_b" type="checkbox" id="3_an0809_b" value="1" /></td> </tr> <tr> <td>c. naţionalitate</td> <td align="center"><input name="3_an0405_c" type="checkbox" id="3_an0405_c" value="1" /></td> <td align="center"><input name="3_an0809_c" type="checkbox" id="3_an0809_c" value="1" /></td> </tr> <tr> <td>d. domiciliu stabil</td> <td align="center"><input name="3_an0405_d" type="checkbox" id="3_an0405_d" value="1" /></td> <td align="center"><input name="3_an0809_d" type="checkbox" id="3_an0809_d" value="1" /></td> </tr> <tr> <td>e. număr telefon fix</td> <td align="center"><input name="3_an0405_e" type="checkbox" id="3_an0405_e" value="1" /></td> <td align="center"><input name="3_an0809_e" type="checkbox" id="3_an0809_e" value="1" /></td> </tr> <tr> <td>f. număr telefon mobil</td> <td align="center"><input name="3_an0405_f" type="checkbox" id="3_an0405_f" value="1" /></td> <td align="center"><input name="3_an0809_f" type="checkbox" id="3_an0809_f" value="1" /></td> </tr> <tr> <td>g. adresă e-mail</td> <td align="center"><input name="3_an0405_g" type="checkbox" id="3_an0405_g" value="1" /></td> <td align="center"><input name="3_an0809_g" type="checkbox" id="3_an0809_g" value="1" /></td> </tr> <tr> <td>h. facultatea absolvită</td> <td align="center"><input name="3_an0405_h" type="checkbox" id="3_an0405_h" value="1" /></td> <td align="center"><input name="3_an0809_h" type="checkbox" id="3_an0809_h" value="1" /></td> </tr> <tr> <td>i. domeniul de studiu</td> <td align="center"><input name="3_an0405_i" type="checkbox" id="3_an0405_i" value="1" /></td> <td align="center"><input name="3_an0809_i" type="checkbox" id="3_an0809_i" value="1" /></td> </tr> <tr> <td>j. media de absolvire</td> <td align="center"><input name="3_an0405_j" type="checkbox" id="3_an0405_j" value="1" /></td> <td align="center"><input name="3_an0809_j" type="checkbox" id="3_an0809_j" value="1" /></td> </tr> <tr> <td>k. alte date care nu sunt înscrise în baza de date, dar sunt trecute în alte documente</td> <td><textarea style="width:220px;" name="3_an0405_k" id="3_an0405_k"></textarea></td> <td><textarea style="width:220px;" name="3_an0809_k" id="3_an0809_k"></textarea></td> </tr> </table> $3_an0405_a=$_POST['3_an0405_a']; $3_an0405_b=$_POST['3_an0405_b']; $3_an0405_c=$_POST['3_an0405_c']; $3_an0405_d=$_POST['3_an0405_d']; $3_an0405_e=$_POST['3_an0405_e']; $3_an0405_f=$_POST['3_an0405_f']; $3_an0405_g=$_POST['3_an0405_g']; $3_an0405_h=$_POST['3_an0405_h']; $3_an0405_i=$_POST['3_an0405_i']; $3_an0405_j=$_POST['3_an0405_j']; $3_an0405_k=$_POST['3_an0405_k']; $3_an0809_a=$_POST['3_an0809_a']; $3_an0809_b=$_POST['3_an0809_b']; $3_an0809_c=$_POST['3_an0809_c']; $3_an0809_d=$_POST['3_an0809_d']; $3_an0809_e=$_POST['3_an0809_e']; $3_an0809_f=$_POST['3_an0809_f']; $3_an0809_g=$_POST['3_an0809_g']; $3_an0809_h=$_POST['3_an0809_h']; $3_an0809_i=$_POST['3_an0809_i']; $3_an0809_j=$_POST['3_an0809_j']; $3_an0809_k=$_POST['3_an0809_k']; $query="INSERT INTO tabela1 ( 3_an0405_a, 3_an0405_b, 3_an0405_c, 3_an0405_d, 3_an0405_e, 3_an0405_f, 3_an0405_g, 3_an0405_h, 3_an0405_i, 3_an0405_j, 3_an0405_k, 3_an0809_a, 3_an0809_b, 3_an0809_c, 3_an0809_d, 3_an0809_e, 3_an0809_f, 3_an0809_g, 3_an0809_h, 3_an0809_i, 3_an0809_j, 3_an0809_k) VALUES (' '$3_an0405_a', '$3_an0405_b', '$3_an0405_c', '$3_an0405_d', '$3_an0405_e', '$3_an0405_f', '$3_an0405_g', '$3_an0405_h', '$3_an0405_i', '$3_an0405_j', '$3_an0405_k', '$3_an0808_a', '$3_an0808_b', '$3_an0808_c', '$3_an0808_d', '$3_an0808_e', '$3_an0808_f', '$3_an0808_g', '$3_an0808_h', '$3_an0808_i', '$3_an0808_j', '$3_an0808_k',)"; the questions are static and the answer can be check box or input text. as u can see a part from the quiz its kinda long. Quote Link to comment Share on other sites More sharing options...
dsp77 Posted March 25, 2010 Author Share Posted March 25, 2010 up Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 25, 2010 Share Posted March 25, 2010 You will want to start by looking at using array(s) in your form - http://www.php.net/manual/en/faq.html.php#faq.html.arrays You can then simply use php array functions, such as a foreach(){} loop to iterate over the data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.