PDA

Click to See Complete Forum and Search --> : creating comments on my server


nokmaster
Jul 30th, 2006, 07:15 AM
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?

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

penagate
Jul 30th, 2006, 07:20 AM
what's it meant to do?

nokmaster
Jul 30th, 2006, 07:39 AM
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,
:)

penagate
Jul 30th, 2006, 07:56 AM
Does your host support file I/O operations?

CornedBee
Jul 31st, 2006, 02:13 AM
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.