You are here: question about variable's scope « PHP Programming Language « IT news, forums, messages
question about variable's scope

Posted by finer recliner on 02/27/07 02:59

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//////////////////////////////////////////

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация