| 
	
 | 
 Posted by OmegaJunior on 02/27/07 07:47 
On Tue, 27 Feb 2007 05:06:02 +0100, Jerry Stuckle  = 
 
<jstucklex@attglobal.net> wrote: 
 
> finer recliner wrote: 
>> i've been playing with the below code for a while now, and i cant get= 
 
>> it to work correctly. the user should be able to input text into a 
>> textbox and upon hitting submit, it will append that text to whatever= 
 
>> is in "newpage.html" and write this new chunk of text to data.txt. 
>>  the final result of my code will be a bit more elaborate, but i can'= 
t 
>> even get this to work. i believe soemthing is wrong the scope of my 
>> variables or how my functions are written or something. it seems 
>> everytime i hit submit, only $text is written to data.txt. $above 
>> seems to be blank in the addHTML function. any suggestions? 
>>  thanks! 
>> -dave 
>>   /////////////////////////start code ///////////////////////////////= 
/ 
>> <html> 
>> <head> 
>> <?php 
>> if ($submit) { 
>> $newdata =3D addHTML($newdata); 
>> $fp =3D fopen("data.txt", "w"); 
>> fwrite($fp, $newdata); 
>> fclose($fp); 
>> } 
>>  $fcurrent =3D fopen("newpage.html", "r"); 
>> $i =3D 0; 
>> while(!feof($fcurrent)){ 
>>         $line =3D fgets($fcurrent, 4096); 
>>         $above .=3D $line; 
>> } 
>> fclose($fcurrent); 
>>  function addHTML($text){ 
>>         global $above; 
>>         $newdata =3D $above . $text; 
>>         return $newdata; 
>> }//end addHTML 
>>  ?> 
>> </head> 
>> <body> 
>> <form action=3D"<? print $PHP_SELF; ?>" method=3D"post"> 
>> <textarea name=3D"newdata" rows=3D"30" cols=3D"80"></textarea> 
>> <br> 
>> <input type=3D"submit" name=3D"submit" value=3D"Submit"> 
>> </form> 
>> </body> 
>> </html> 
>> //////////////////////////////////end 
>> code////////////////////////////////////////// 
>> 
> 
> In addition to Klarth's comments, you shouldn't use global variables. = 
If  = 
 
> you would have passed $above to this function (as a second parameter) = 
 = 
 
> your problem would have been more obvious (just one of the reasons not= 
  = 
 
> to use globals). 
> 
> 
 
Use $_POST[] instead. 
 
I agree with Klarth: the order of the statements does not compute.  = 
 
Suggestion: write down, in small sequential steps, how the script should= 
  = 
 
function. Make sure that every next step gets all its data from a previo= 
us  = 
 
step. Then write the actual script. 
 
-- = 
 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
 
  
Navigation:
[Reply to this message] 
 |