WRITE a php<

admin

Administrator
Staff member
Hmm....Im a new kid on the block...

why my php can't WRITE to the server (i use a file as the database --polling database, guestbook database)

or in other way...can u explain me how to create a guestbook using a file as a database (not SQL, MySQL or other else)

thank you !

regards,
Riowhat is the code you are using that doesn't work?

mysql is better than a file if you can use that.hmmmm, i think he means his php cant write to the server as he cannot use a database and he would like the code for a guestbook with text, i think.. heres one that i whipped up, still VERY dodgy, i recommend that you don't use it, it needs a lot of work...

gb.php

<?php
$filename = "gb.txt"; // Change this to whatever txt file you want

$fileopen = fopen($filename, "r");
$open = fread($fileopen, filesize($filename));
fclose ($fileopen);

if(filesize($filename) == 0) { // If the filesize of the filename is nothing, display no entries
echo "No entries, <a href=http://www.htmlforums.com/archive/index.php/\"sign.html\">Please Sign!</a>\n";
exit();
}

$line = explode("\n", $open);

$i = 0;
while($i <= sizeof($line)) {

$gb = explode(":", $line[$i]);

echo "<table width=\"300\" border=\"1\">
<tr>
<td>Name - " . $gb[0] . "<br>
Email - <a href=http://www.htmlforums.com/archive/index.php/\"" . $gb[1] . "\">" . $gb[1] . "</a></td>
</tr>
<tr>
<td>Comment - <br>" . $gb[2] . "</td>
</tr>
</table><br><br>\n";
$i++;
}

echo "<a href=http://www.htmlforums.com/archive/index.php/\"sign.html\">Sign!</a>";
?>


sign.html

<html>
<body>
<form method="POST" action="mod.php">
Name : <input type="text" size="15" name="name"><br>
Email : <input type="text" size="15" name="email"><br>
Comment : <textarea rows="2" cols="20" name="entry"></textarea><br>
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></form>
</body>
</html>


mod.php

<html>
<body>
<?php
$name = $_POST[name];
$email = $_POST;
$comment = $_POST[entry];

if (empty($name) || empty($email) || empty($comment)) {

if (empty($name)) {
echo "Please Insert a name....<br>\n";
}

if (empty($email)) {
echo "Please Insert an email....<br>\n";
}

if (empty($name)) {
echo "Please Insert a comment....<br>\n";
}
exit();
}
$entry = "" . $name . ":" . $email . ":" . $comment . "";

$entry_file = fopen("gb.txt", "a");
fwrite($entry_file, $entry . "\n\n");
fclose($entry_file);
?>
Entry Added. <a href=http://www.htmlforums.com/archive/index.php/"gb.php">Return Here</a><br>
</body>
</html>


and create a text document that matches the name of the one that you put as $filename in gb.php

Please bear in mind, that this is not a script that should actually be used, just to be taught off :) there are a few problems with it i know, if anyone would like to add i would appreciate it too :)

dm
 
Back
Top