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