creating comments on my server
Hi, im creating a txt from my web.. but when i check it in my cpanel why Comments isn't create?
this is the code.. when i test this from my localhost its working properly..
whats wrong with this?
PHP Code:
<table width="100%" height="100%">
<?php
// filename
$file = "Comments.txt";
// validate form
function form_validate () {
if (sizeof($_POST) < 1) return false;
foreach ($_POST as $name => $value) {
if (empty($name) || !isset($name)) {
return false;
}
}
return true;
}
function blank_replace ($str) {
return str_replace (" ","|",$str);
}
function stick_escape ($str) {
return str_replace ("|"," ",$str);
}
if (form_validate()) {
$fp = fopen ($file,"at");
fwrite ($fp,uniqid(rand(),true)."\t".blank_replace($_POST['name'])."\t".blank_replace($_POST['comment'])."\n");
fclose ($fp);
}
if (!file_exists($file)) {
echo "Here, no commments"; //sorry my bad english
} else {
$fp = fopen ($file,"r");
while ($info = fscanf ($fp,"%s\n%s\n%s\n\n")) {
list ($id,$name,$comment) = $info;
?>
<table border="1" width="47%">
<tr>
<td width="26%">Name : </td>
<td width="74%"><?=stick_escape($name)?></td>
</tr>
<tr>
<td width="26%">Comment:</td>
<td width="74%"><?=stick_escape($comment)?></td>
</tr>
</table>
<br>
<?php
}
}
?>
<hr>
<form action="index.php" method="post">
Name :
<br>
<input name="name" type="text" size="30">
<br>
Comment :
<br>
<textarea cols="30" name="comment"> </textarea>
<br>
<input type="submit" value="Submit">
</form>
</table>
Re: creating comments on my server
Re: creating comments on my server
that is a simple shout box.. i want the data save in txt format "Comments.txt"
when the user visited my site he will post the Name and Comments and if he press submit the data will record on comments.txt
br,
:)
Re: creating comments on my server
Does your host support file I/O operations?
Re: creating comments on my server
You should check the file handle directly after opening it.
Also, the script should emit an error message if it can't open the file. If it doesn't, enable error reporting.