|
Posted by finer recliner on 02/27/07 04:12
On Feb 26, 10:12 pm, "Klarth" <kah....@gmail.com> wrote:
> On Feb 27, 11:59 am, "finer recliner" <finerrecli...@gmail.com> 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 = addHTML($newdata);
> > $fp = fopen("data.txt", "w");
> > fwrite($fp, $newdata);
> > fclose($fp);
>
> > }
>
> > $fcurrent = fopen("newpage.html", "r");
> > $i = 0;
> > while(!feof($fcurrent)){
> > $line = fgets($fcurrent, 4096);
> > $above .= $line;}
>
> > fclose($fcurrent);
>
> > function addHTML($text){
> > global $above;
> > $newdata = $above . $text;
> > return $newdata;
>
> > }//end addHTML
>
> > ?>
> > </head>
> > <body>
> > <form action="<? print $PHP_SELF; ?>" method="post">
> > <textarea name="newdata" rows="30" cols="80"></textarea>
> > <br>
> > <input type="submit" name="submit" value="Submit">
> > </form>
> > </body>
> > </html>
> > //////////////////////////////////end
> > code//////////////////////////////////////////
>
> Look at the order of your statements. You are calling your addHTML
> function before that makes use of the global variable $above, before
> $above gets set.
moving the addHTML function to the very beginning of my php block does
not change anything. I also tried moving it between the if(submit){}
block and the $fcurrent = fopen(...); line. no change. other ideas?
Navigation:
[Reply to this message]
|