I can't submit any data into a text file, in a lower directory, using forms, and the 'fputs' function in php. I removed the javascript alert that I had. Letting me know every thing worked out ok. Even though it claims the information has been submitted, nothing shows up in the text file. Here's my code:

<?php

$out = fopen("rs/xpdb/fishingxp.txt", "a");

if (!$out) {
    print("Could not append to file, please contact blah blah");
    exit;
}

fputs($out,"<td align=left valign=top bgcolor=#000000><font size=1 color=#FFFFFF><b>\n");
fputs($out,"$skill\t");
fputs($out,"</b></font></td>\n");
fputs($out,"<td align=left valign=top bgcolor=#000000><font size=1 color=#FFFFFF><b>\n");
fputs($out,"$xp\t");
fputs($out,"</b></font></td>\n");
fputs($out,"<td align=left valign=top bgcolor=#000000><font size=1 color=#FFFFFF><b>\n");
fputs($out,"$level\t");
fputs($out,"</b></font></td>\n");
fputs($out,"<td align=left valign=top bgcolor=#000000><font size=1 color=#FFFFFF><b>\n");
fputs($out,"$bored\t");
fclose($out);
?>

I've even removed all "table tags" from the code, and left it bare. I've checked the submission forms (form method="post" action="rs/fishxp.php"). I get no errors at all. I've set diretory and file permissions:

Folder -> xpdb (permissions - 777)
File -> fishingxp.txt (permissions - 777)

I'm using the 'include' function to display everything in "rs/xpdb/fishingxp.txt", which I've checked. But, I can't even get anything submitted into the text file at all.

Here's the file I'm using to submit into the php script, then onto the txt file itself. It's in the above directory. I've checked all paths, which are correct.

<table width="50%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle">
<font size="1"><b>Fishing Skill:</b></font></tD>
<td align="center" valign="middle">
<form method="post" action="rs/fishxp.php">
<INPUT TYPE="TEXT" NAME="skill" size="25"></td></tr>
<tr>
<td align="left" valign="middle">
<font size="1"><b>XP Given:</b></font></td>
<td align="center" valign="middle">
<INPUT TYPE="TEXT" NAME="xp" size="25"></tR></td>
<tr>
<td align="left" valign="middle">
<font size="1"><b>Level Required:</b></font></td>
<td align="center" valign="middle">
<INPUT TYPE="TEXT" NAME="level" size="25"></tR></td>
<tr>
<td align="left" valign="middle">
<font size="1"><b>Level Required:</b></font></td>
<td align="center" valign="middle">
<INPUT TYPE="TEXT" NAME="bored" size="25"></tR></td>
<Tr>
<td align="left" valign="middle">
<font size="1"><b>Submit:</b></font></td>
<td align="center" valign="middle">
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit Post">&nbsp;&nbsp;<INPUT TYPE="RESET" NAME="Reset" VALUE="Clear Fields">
</form>
</tR></td></table>

Any ideas on what I'm doing wrong?

    i can't seem anything wrong with your script

    try debugging the result of fputs and see if its a valid number

    [man]fwrite[/man]

      Do you have write permissions set on the folder?

        Yes, all my permissions are correct.

          Put in the full path to the file (/home/http/html/???).
          It works for me.

            5 days later

            I got the script to submit the data into the text file, however it's refusing to put in any other code into the text file.

            <?php
            // Set the file name
            $file = "fishing.txt";
            // setting the function
            $do = fopen($file, 'a');
            
            // making sure i can open the file
            
            if (!$do) {
            print("could open file kid");
            exit;
            }
            
            // defining what goes into the file
            
            $0 = "<tr>";
            $1 = "<td align=\"left\" valign=\"top\" bgcolor=\"#DBD5C7\">";
            $2 = "<font size=\"1\">";
            $3 = </font></td>";
            $3 = "</tr>";
            
            fputs($do, "$0 \n");
            fputs($do, "$1 \n");
            fputs($do, "$2 \n");
            fputs($do, "$item \n");
            fputs($do, "$3 \n");
            fputs($do, "$0 \n");
            fputs($do, "$1 \n");
            fputs($do, "$2 \n");
            fputs($do, "$xp \n");
            fputs($do, "$3 \n");
            fputs($do, "$0 \n");
            fputs($do, "$1 \n");
            fputs($do, "$2 \n");
            fputs($do, "$rlevel \n");
            fputs($do, "$3 \n");
            fputs($do, "$4 \n");
            
            fclose($do);
            
            ?>
            

            I've tried every thing, I thought perhaps php was ignoring the html code, so I stripped all html tags in $0 through $4 and just put 'test' in there, but even the text wouldn't show up. I've also tried..

            fputs($do, "<td align=\"left\" valign=\"top\" bgcolor=\"#DBD5C7\"><font size=\"1\">$item </font></td>\n");
            fputs($do, "<tr><td align=\"left\" valign=\"top\" bgcolor=\"#DBD5C7\"><font size=\"1\">$xp </font></td>\n");
            fputs($do, "<tr><td align=\"left\" valign=\"top\" bgcolor=\"#DBD5C7\"><font size=\"1\">$rlevel </font></td></tr>\n");
            

            It will take "$item,$xp and $rlevel", it ignores every thing else. What am I doing wrong?

            Thanks for any help 🙂

              Write a Reply...