long winded explination...
I am writing a HTML form that users can enter various detials and upon clicking "add" it writes various details to various different files.
So, the users selects what they want using checkbox's, more then one can be selected.
Select this if you want this product 1 []
Select this if you want this product 2 [*]
Select this if you want this product 3 [*]
etc etc
HTML SNIPPET....
<input name="q" type="checkbox" value="Severe_Thunderstorm_Warning(1).txt">
Severe Thunderstorm Warning (1)<br>
<input name="q2" type="checkbox" value="Severe_Thunderstorm_Warning(2).txt">
Severe Thunderstorm Warning (2)<br>
<input name="q3" type="checkbox" value="Severe_Thunderstorm_Warning_(3).txt">
Severe Thunderstorm Warning (3)<br>
<input name="q4" type="checkbox" value="Road_Weather_Alert.txt">
Road Weather Alert<br>
<input name="q5" type="checkbox" value="Severe_Weather_Warning.txt">
Severe Weather Warning<br>
so i have the array/write setup like this for when the user has click sumbit...
<?php
$warnings = array($_POST[q],$_POST[q2],$_POST[q3],$_POST[q4],$_POST[q5]);
foreach ($warnings as $w){
$warning = $w;}
//then the file write code
$rContents = "$filename";
$dir = "Users";
if (!$handle = fopen("$dir/$warning", 'awb+')) {
echo "<br>Cannot open file ($warning)";
exit;
}
// Write content to file.
if (fwrite($handle,"\r\n $rContents") === FALSE) {
echo "<br>Cannot write to file ($warning)";
exit;
}
echo "<br>Success, wrote ($rContents) to file ($warning)";
fclose($handle);
?>
ok, it will do what it is suppose to do (write file), only IF the $_POST[q5] has been slectected on the HTML posting page, BUT will only write THAT one file, in this case...
<input name="q5" type="checkbox" value="Severe_Weather_Warning.txt"> Severe Weather Warning<br>
so it doesn't see the rest of the array values except for the last one...
so $_POST[q5] = Severe_Weather_Warning.txt...
the result is (even with q4, q3, q2 selected...)
Success, wrote (what_ever.txt) to file (What_ever_this_is.txt)
(what_ever.txt is set in the... $rContents/$filename )
IT should write the other files corrosponding with q2 q3 q4 etc etc but it doesn't..
WHEN q5 hasn't been selected on the html post page, the i get this error:
Warning: fopen(Users/): failed to open stream: Is a directory in /home/canberra/public_html/wwxs/adduser.php on line 48
Cannot open file ()
...
I got told to add in a While loop on the $dir line but..
When i add in the while loop, and have q5 unslected, the same thing occurs, when i have q5 selected the while loop runs indefinatley, rewriting the same (q5) file over and over....
Strange but true...