[SOLVED] fwrite question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

fwrite question

Post by fresh »

hello,

im trying to write to an htm doc, which will be generated from PHP like so;

Code: Select all

// check if pass is correct
$sp = $_GETї'name'];
$perm = $_GETї'pass'];
if(!$sp) {
echo "We're sorry... you must enter a name to login.";
} else {

if($perm == "0"){   //if it's ALL good move to main

//opens file for writing
$fp = fopen("".$sp.".htm","a+");

//write string to htm file
fwrite($fp, $sp);
fclose($fp);
now in the above example, the users name is saved with an htm ext, given the user a mini account, without the use of sql, etc... which is what I am trying to avoid... what I would like is to dynamically print a div box and then eventually as the user progresses, the users page will update with new info...

if I can get a confirmation on this one question I feel like I could wing the rest...

so, is it correct to do this:

Code: Select all

fwrite($fp, $sp);
echo "<div style="blah" etc...>";
echo "etc...";
fclose($fp);
would that write the div to the user.htm file? I know I could throw the variables in with the html code and use those to help in updating dynamically, so all i want to know is how to write html code to an htm file dynamically via PHP, while passing variables...

thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no..

Code: Select all

$str = '<div style="blah" etc....>';
fwrite($fp,$str);
would however.
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

great

Post by fresh »

so would I just go like this:

Code: Select all

$str1 = "<div style='blah'>";
$str2 = "blah";
$str3 = "</div>";
fwrite($fp, $str1, $str2, $str3);

thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fwrite($fp,$str1.$str2.$str3);
or
fwrite($fp,$str1);
fwrite($fp,$str2);
fwrite($fp,$str3);
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

nice

Post by fresh »

thanks alot!!! :D
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

new question same subject

Post by fresh »

i noticed that this could be bad because if someone inputs a name already existant, then it would probably overwrite that users file... how could I code an ' if this file exists say this' script... remember I am using htm files to store the data not sql...

thanks in advance
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

yes

Post by fresh »

that did it... thank you guys alot... php is an awesome language isn't it? :D
Post Reply