Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-05-2004, 07:09 AM Array Error
Novice Talker

Posts: 11
Trades: 0
long winded explination follows......
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 Code:

<?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...
|-SiM-| is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-12-2004, 03:08 AM
Novice Talker

Posts: 11
Trades: 0
no clues guys???
|-SiM-| is offline
Reply With Quote
View Public Profile
 
Old 08-12-2004, 05:34 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
first of all, if not all the boxes are checked, you're trying to seed the array with non existent values. Secondly, $warning will only ever return the last of the selected boxes, because of the way you set its value. Thirdly, is there a reason for opening this file in binary mode? So far as I can see, its supposed to have asscii content.
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-12-2004, 11:40 PM
Novice Talker

Posts: 11
Trades: 0
no reason for binary mode..

So how do i fix the problems then?
|-SiM-| is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Array Error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13894 seconds with 12 queries