Connecting Tech Pros Worldwide Help | Site Map

printing $_POST data to text file

anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#1: Aug 24 '09
hi i've got this code that writes data to a text file. When i test it with a standard array eg array(1,2,3) it works perfectly fine but when i try it with $_POST['myData'] i get the error message

Warning: Invalid argument supplied for foreach() in /home/theau10/public_html/resources/captionSaveB.php on line 23

Warning: Invalid argument supplied for foreach() in /home/theau10/public_html/resources/captionSaveB.php on line 38

Warning: Invalid argument supplied for foreach() in /home/theau10/public_html/resources/captionSaveB.php on line 53

here is my code.....can someone point me to the incorrect code....i cant see where its going wrong

Expand|Select|Wrap|Line Numbers
  1. $file = "upload/$random_digit/gallery.txt";
  2. $imgHandle = fopen($file, 'w+') or die("can't open file");
  3.  
  4.     $iv= 1;
  5.     $lQ = ',';
  6.     $imgAry = $_POST['imageT'];
  7.  
  8.     $stringData = "&imgLoc=";
  9.     fwrite($imgHandle, $stringData);
  10.  
  11.         foreach($imgAry as $key => $value){
  12.             fwrite($imgHandle,$value .$lQ);
  13.         }
  14.  
  15. fclose($imgHandle);
  16.  
  17. $tmbHandle = fopen($file, 'a+') or die("can't open file");
  18.  
  19.     $iv= 1;
  20.     $tQ = ',';
  21.     $tmbAry = $_POST['thumbnailT'];
  22.  
  23.     $stringData = "&tmbLoc=";
  24.     fwrite($tmbHandle, $stringData);
  25.  
  26.         foreach($tmbAry as $key => $value){
  27.             fwrite($tmbHandle,$value .$tQ);
  28.         }
  29.  
  30. fclose($tmbHandle);
  31.  
  32. $capHandle = fopen($file, 'a+') or die("can't open file");
  33.  
  34.     $iv= 1;
  35.     $cQ = ',';
  36.     $capAry = $_POST['captionT'];
  37.  
  38.     $stringData = "&imgCap=";
  39.     fwrite($capHandle, $stringData);
  40.  
  41.         foreach($capAry as $key => $value){
  42.             fwrite($capHandle,$value .$cQ);
  43.         }
  44.  
  45. fclose($capHandle);
  46.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Aug 24 '09

re: printing $_POST data to text file


it seems that the input values ($_POST['…']) are not arrays. you can check with var_dump().
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#3: Aug 25 '09

re: printing $_POST data to text file


on the form the names are set on imageT[], thumbnailT[] and captionT[].

once submitted i test to make sure that they are arrays and use print_r and they show as an array perfectly fine
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Aug 25 '09

re: printing $_POST data to text file


Quote:

Originally Posted by anfetienne View Post

once submitted i test to make sure that they are arrays and use print_r and they show as an array perfectly fine

even when you test it before the foreach loop?
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#5: Aug 25 '09

re: printing $_POST data to text file


yup even when i test it before the loop it shows that they are all arrays with all the values i enter from my form
Reply