hi, I'm always getting this error code.. Warning: Invalid argument supplied for foreach() in /is/htdocs/wp1024629_Z9I2JQPK6Z/www/fragebogen/questionnaire.php on line 38 I've found out in forum that this error occurs when the argument is not an array. but I don't know what I've done wrong in my code. pls help me. this is my php form-processing file. <? $myFile = "questionnaire.txt"; $fh = fopen($myFile, 'r'); if(filesize($myFile)>0){ $theData = fread($fh, filesize($myFile)); } fclose($fh); $fh = fopen($myFile, 'w') or die("can't open file"); foreach($pre12 as $p12){ $stringData=$stringData.$p12." \n"; } echo $stringData; fwrite($fh, $stringData); fclose($fh); ?> and this is the fragment of my html form, of which i want to get the values. <p> 12.Did the feedback mechanism during the game (through sims, news agents etc) had any kind of impact on your game activity? <em><font size="2">(more than one answer possible).</font></em> </p> <input type="checkbox" name="pre12[]" value="It motivated me">It motivated me <br> <input type="checkbox" name="pre12[]" value="It helped me to take new steps to overcome the problems">It helped me to take new steps to overcome the problems <br> <input type="checkbox" name="pre12[]" value="It didn't have any impact on me">It didnt have any imapct on me <br> <input type="checkbox" name="pre12[]" value="It made me nervous">It made me nervous <br> <input type="checkbox" name="pre12[]" value="It influenced my game activity in some other way(not mentioned above)">It influenced my game activity in some other way (not mentioned above). <br> <textarea name="pre12-textarea" rows="5" cols="80"></textarea>
Also remember that with checkboxes, only those that are ticked are returned to the server. Therefore, if none of those are ticked, none are returned and therefore the array will not be defined. As reza56 said, too, maybe you need to refer to it via the $_REQUEST variable.
Not sure what version of PHP you're using, or is $_POST if the correct method (been away from php a while). But id do this: $data = ''; if (is_array($_POST['pre12'])) { foreach($_POST['pre12'] as $pre12) { $data .= $pre12 . "\r\n"; } } else { $data = $_POST['pre12']; } if (strlen($data) > 0) { // write your data to text file here } else { // no data was given.. echo 'No Data'; } PHP: Hope that helps. Matt.
hi! Thank you for all the help! now I've got a new problem.. the web browser doesn't seem to be able to read the "names" of the input formulars.. <input type="text" name="age"> for example no value will be sent for "age"... if I change the method to "GET", it looks like http://www.xxxxxxxx.com/example.php?=&=&=&=&=&? what coulld be the reason?? It did work till today.. Then I've changed the character Encoding of my php processing page with my php editor.. could that be the reason..? <html> <head> <title>SimCity Questionnaire</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body text="#3333FF"> <center> <img src="tuwien.png"><br><br><br> </center> <center> <font color="black"> English <a href="questionnaire_german.html">Deutsch</a> <a href="questionnaire_korean.html">ÕœêµÂ어</a></center></font> <p><em><font color="#3333FF">We are students from Vienna doing a research on e-learning methods.<br> This questionnaire is only a help material for us to analyze/confirm/reject our view on our research work entitled „Learning from Simulator games”. <br> We have chosen “Simcity” and some other Simulator games to analyze different aspects of already available simulators for learning purpose. However this form limits only to Simcity. Please help us in making our work successful by sharing us your views on following questions.</font></em></p> <p><br> <font color="#3333FF"><strong>Name: </strong></font></p> <form name="questionnaire" method="POST" action="questionnaire.php"> <input type="text" name="name""> <p><font color="#3333FF"><strong> Age: </strong></font></p> <input type="text" name="age"> <p align="center"><font color="#3333FF" size="5"><strong>SimCity Questionnaire</strong></font></p> <p> <font color="#3333FF"> 1.Did you have any kind of imagination of how your city could be before getting started? </font> </p> <input name="pre1" type="radio" value="yes"><font color="#3333FF">Yes</font> <br> <input name="pre1" type="radio" value="no"><font color="#3333FF">No</font> <br> <input type="radio" name="pre1" value="A rough imagination">A rough imagination <br> <p> 2.Did you play tutorials as you started playing SimCity? </p> <input type="radio" name="pre2" value="yes">Yes <br> <input type="radio" name="pre2" value="no">No <p> 3.Did the tutorial help to get into the game? </p> <input type="radio" name="pre3" value="yes, it helped a lot">Yes, it helped a lot <br> <input type="radio" name="pre3" value="yes, but only a little">Yes, but only a little <br> <input type="radio" name="pre3" value="no, not really">No, not really <br> <input type="radio" name="pre3" value="no, not at all">No, not at all <p> 4.Did you have any plans/sketch made up of your city before beginning to play? </p> <input type="radio" name="pre4" value="yes">Yes <br> <input type="radio" name="pre4" value="no">No <p> 5.If Yes, what were the basic concepts of your strategy?<font size="2">(For e.g The city should have high education system, high security etc)</font> </p> <p> <textarea name="pre5" rows="5" cols="80"></textarea> </p> <p> 6.Did you have the feeling that your approach needs change during the play? </p> <input type="radio" name="pre6" value="yes">Yes <br> <input type="radio" name="pre6" value="no">No <p> 7.Did you take any kind of new steps to shape your city that varied form your original plan? </p> <input type="radio" name="pre7" value="yes">Yes <br> <input type="radio" name="pre7" value="no"> No <p> 8.Did you save the game status during the game? </p> <input type="radio" name="pre8" value="yes">Yes <br> <input type="radio" name="pre8" value="no">No <p>9.Were you satisfied with the outcome of the game?</p> <input type="radio" name="pre9" value="I was fully satisfied with my performance"> I was fully satisfied with my performance <br> <input type="radio" name="pre9" value="It was ok">It was ok <br> <input type="radio" name="pre9" value="I could have done better">I Could have done better <br> <input type="radio" name="pre9" value="I was not satisfied">I was not satisfied <br> <p>10.Do you think your Strategy was good enough? Please rank from 1-5 ( <font size="2"><em>1.very good………5.Not satisfied</em></font>).</p> <input type="radio" name="pre10" value="1">1 <br> <input type="radio" name="pre10" value="2">2 <br> <input type="radio" name="pre10" value="3">3 <br> <input type="radio" name="pre10" value="4">4 <br> <input type="radio" name="pre10" value="5">5 <br> <p>11.Do you think you can perform better next time?</p> <input type="radio" name="pre11" value="Yes, for sure">Yes, for sure <br> <input type="radio" name="pre11" value="Most probably yes">Most probably yes <br> <input type="radio" name="pre11" value="no">No <br> <input type="radio" name="pre11" value="I don't know">I don't know <br> <p>12.Did the feedback mechanism during the game (through sims, news agents etc) had any kind of impact on your game activity? <em><font size="2">(more than one answer possible).</font></em></p> <input type="checkbox" name="pre12[]" value="It motivated me">It motivated me <br> <input type="checkbox" name="pre12[]" value="It helped me to take new steps to overcome the problems">It helped me to take new steps to overcome the problems <br> <input type="checkbox" name="pre12[]" value="It didn't have any impact on me">It didnt have any imapct on me <br> <input type="checkbox" name="pre12[]" value="It made me nervous">It made me nervous <br> <input type="checkbox" name="pre12[]" value="It influenced my game activity in some other way(not mentioned above)">It influenced my game activity in some other way (not mentioned above). <br> <textarea name="pre12[]" rows="5" cols="80"></textarea> <p>13.Do you think there were enough feedbacks for your strategies to evaluate your plan?</p> <input type="radio" name="pre13" value="yes">Yes, there were just right amount of feedbacks <br> <input type="radio" name="pre13" value="no">No, I would have liked more feedback about my strategy <br> <p>14.Did you have fun during the game?</p> <input type="radio" name="pre14" value="yes">Yes<br> <input type="radio" name="pre14" value="no">No <p align="center"> </p> <p>15.How did you find the Graphic of the game? Please rank from 1-5<font size="2"><em> ( 1.very good………5.Not satisfied)</em></font></p> <input type="radio" name="pre15" value="1">1 <input type="radio" name="pre15" value="2">2 <input type="radio" name="pre15" value="3">3 <input type="radio" name="pre15" value="4">4 <input type="radio" name="pre15" value="5">5 <p>16.was the interface of the game easy to learn?</p> <input type="radio" name="pre16" value="yes">Yes<br> <input type="radio" name="pre16" value="it was ok">it was ok<br> <input type="radio" name="pre16" value="no">No <p>17.Did you have any opportunity to discuss about your strategy with someone else?</p> <p> <input type="radio" name="pre17" value="yes">Yes</p><p> <input type="radio" name="pre17" value="no">No </p> <p>18.(if yes to previous question) with whom did you discuss?</p> <input type="checkbox" name="pre18[]" value="with friends">with friends<br> <input type="checkbox" name="pre18[]" value="internet forum">I discussed my strategy in an internet forum<br> <p>19.(if yes to previous question) did you benchmark or combine your basic strategy with those of others after the discussion?</p> <input type="radio" name="pre19" value="yes">Yes<br> <input type="radio" name="pre19" value="no">No<br> <p>20.(if yes to previous question) did you have the feeling that your strategy had improved after the discussion?</p> <input type="radio" name="pre20" value="yes,always">Yes,always<br> <input type="radio" name="pre20" value="mostly yes">mostly yes<br> <input type="radio" name="pre20" value="rarely">rarely<br> <input type="radio" name="pre20" value="no">no<br> <p>21.Would you still play the game in future?</p> <input type="radio" name="pre21" value="yes">Yes<br> <input type="radio" name="pre21" value="no">No <br> <input type="radio" name="pre21" value="I don't know">I dont know<br> <p>22.(if no to previous question) What is the reason that you don't want to play the game in the future?</p> <textarea name="pre22" rows="5" cols="80"></textarea> <p>23.What are the "fun factors" of SimCity in your opinion?</p> <input type="checkbox" name="pre23[]" value="the realistic model of the realworld">the realistic model of the real world <br> <input type="checkbox" name="pre23[]" value="the game concept, the idea of the game">the game concept, the idea of the game<br> <input type="checkbox" name="pre23[]" value="good graphic and sound">good graphic and sound<br> <input type="checkbox" name="pre23[]" value="other factors">other factors <textarea name="pre23[]" rows="3" cols="80"></textarea> <p>24.Were there any differences between your imagination of city and the model in Simcity?</p> <input type="radio" name="pre24" value="yes">Yes<br> <input type="radio" name="pre24" value="no">No <br> <p>25.Have you gained any kind of new knowledge about the processes in a city after playing simcity?</p> <input type="radio" name="pre25" value="yes">Yes<br> <input type="radio" name="pre25" value="no">No <br> <p>26.Do you think Simcity can be a good learning tool to learn about a city? </p> <input type="radio" name="pre26" value="yes">Yes <br> <input type="radio" name="pre26" value="no">No <br> <input type="radio" name="pre26" value="as a help material only">As help material only, cant be as effective as book learning <br> <p>27.(if no to the previous question)If you don't think that sim city can be a alternative learning method, what is the reason?<br> <textarea name="pre27" rows="5" cols="80"></textarea> <p>28.Do you think such simulators could be a good substitute to book-learning process in general?</p> <input type="radio" name="pre28" value="yes">Yes <br> <input type="radio" name="pre28" value="no">No <br> <input type="radio" name="pre28" value="not completely">Not completely <br> <p>29.What is the most important feature/property that makes a good simulation game in your opinion?</p> <textarea name="pre29" rows="5" cols="80"></textarea> <p>30.What is the least important feature/property that makes a good simulation game in your opinion?</p> <textarea name="pre30" rows="5" cols="80"></textarea> <p>31.What kinds of simulation games have you played to date? list them..</p> <textarea name="pre31" rows="5" cols="80"></textarea> <p>32.Are there any simulation games out of the list of the previous question, of which you think that you have gained some new skills or knowledge afger playing it? pls list those games.</p> <textarea name="pre32" rows="5" cols="80"></textarea> <p>33.What do you think simulation games like SimCity needs to become a good learning method?</p> <input type="checkbox" name="pre33[]" value="more realistic model of the real world">more realistic model of the world<br> <input type="checkbox" name="pre33[]" value="better, easy to learn user-interface">better,easy to learn user-interface<br> <input type="checkbox" name="pre33[]" value="better graphics and sounds">better graphics and sounds<br> <input type="checkbox" name="pre33[]" value="a better guide which helps you playing the game">a better guide which helps you playing the game<br> <input type="checkbox" name="pre33[]" value="more fun!">more fun!<br> <input type="checkbox" name="pre33[]" value="other factors">other factors <textarea name="pre33[]" rows="3" cols="80"></textarea> <p>34.What would you choose if you had the possibility?</p> <input type="radio" name="pre34" value="learning by book">Learning by book<br> <input type="radio" name="pre34" value="learning by simulator">Learning by Simulator <br> <p> <input type="submit" value="send"> </p> </form> <p align="center"><font color="#3333FF" size="5"><strong>Thank you for your participation in our survey!</strong></font></p> <p> </p> <p> </p> <p> </p> <p><br> <font color="#CCCCCC"> </font> </p> </body> </html>
Looks like you have a doublequote on this line: <input type="text" name="name""> That might cause it. Just by looking, i'm thinking this is the most likely cause since it's the first input field.