cyclefiend2000 wrote:

the last line does print and looks like it should.

Good.

dalecosp,

the code you gave does the same thing as the code i was previously using.

Err, no, it doesn't. Or, more properly, it does in your situation, but in some situations, it would not do the same thing. For example, if the file didn't exist. However, that's prolly not important, as you note that it is working in your situation.

IMPORTANT: You may wish to replace that URL in your code examples with a non-working example; you may make your site a target for attack since PHPBuilder forums are widely known and publicly archived.

Finally, is there any reason why you call [man]fopen/man with 'a' in the first example and 'a+' in the second?

    it is a virtual address only accessible from our internal network.

    i originally had both fopen() commands using 'a+'. i took out the + to see if that made a difference.

      Did you turn error_reporting to E_ALL for your debugging?

      You also don't need ./ in front of your file name since the server will look in the current working directory anyways.

        Kudose wrote:

        Did you turn error_reporting to E_ALL for your debugging?

        not sure how to do that. i will do some searching.

          error_reporting(E_ALL);

          [man]error_reporting[/man]

            ok try this:

            $new_no = $_POST['new_no'];
            $new_name = $_POST['new_name'];
            $myFile = "./job_list.txt";
            $fh = fopen($myFile,'a+') or die("can't open file");
            $new_array = ($new_no, $new_name);
            $new_list = implode("-", $new_array);
            $new_list = $new_list . "<br />";
            fwrite($fh,$new_list);
            fclose($fh);
            echo $new_list;
            
              $new_list = $new_list . "<br />";

              i need a new line character for a text file. not for html.

              i did try using implode to define the variable. i get the same results.

                Kudose wrote:
                error_reporting(E_ALL);

                [man]error_reporting[/man]

                i added the line above to my php file. the output gives no errors.

                edit: i am at a give up point. i may have to take the option to add a new job number out, and add it manually to the text file myself.

                  try the following:

                  if(!(isset($_POST['new_name'])))
                  {
                     die("Problem lies with new_name");
                  }
                  

                  or this

                  if(is_null($_POST['new_name']))
                  {
                     die("Problem lies with new_name");
                  }
                  

                  that way youll see if that causes the problem

                    cyclefiend2000 wrote:

                    i added the line above to my php file. the output gives no errors.

                    Did you add it before all the functions you are calling ... maybe at the top of the file?

                    Try this:

                    <?php
                    error_reporting(E_ALL);
                    $new_no = $_POST['new_no'];
                    $new_name = $_POST['new_name'];
                    if(!isset($new_no) || !isset($new_name))
                      die('new_no or new_name is not set');
                    $myFile = "job_list.txt";
                    $fh = fopen($myFile,'a+') or die("can't open file");
                    $new_array = array($new_no, $new_name);
                    $new_list = implode("-", $new_array);
                    $new_list = $new_list . "<br />";
                    fwrite($fh,$new_list) or die('Could not write to file.');
                    fclose($fh) or die('Could not close file.');
                    ?>
                    

                      OK, tell us more about the setup. In particular, what OS, and what permissions are on the file? Maybe I'm misunderstanding, is the file actually having "Null" written to it, or is nothing being added to the file?

                        i did a "chmod 777" on all the files in that directory. at least for now.

                        the OS is SME Server 6.0.1-01

                        php version - 4.1.2

                        mysql version - 3.23.56

                        i put examples of what is written to the text file in my initial post. basically, it should write something like this...

                        207.100~Job Name

                        but instead it writes something like....

                        ~
                        207.100~Job Name

                        the line isnt "NULL" and it does write something. it just adds and extra line with only a "~". I use this text file to put items in a drop down menu so i really dont want the extra line with the "~" inserted.

                        i will be happy to add screenshots tomorrow when i get to work if you think that might help.

                          Of the top of my head, this behavior is indicative of a, let's say, "faulty", looping scheme --- but I could be wrong. It does appear, however, that the script write one iteration with the variables undefined prior to writing one correctly. I'll check your PHP on the first page again....

                            I don't see any looping structure there, though; is this (on the first page) the entire script?

                            Y'know, prolly at this point, I'd just slap it with a dirty hack. Something like:

                            system("echo $new_list >> $myfile");

                            ... and start doing other work. YMMV.

                              the original post contains all the code as i had originally wrote it. short and sweet... no loops.

                              i will try your hack. what is it supposed to do?

                                It takes the place of fopen, fwrite, fclose, etc. Might not be safe if there's a chance of lots of ppl using the system at once. You've never used this sort of thing in your shell?

                                [473 Wed 31.Oct.2007 9:43:03
                                [kadmin@archangel][~]
                                # touch foo
                                
                                [474] Wed 31.Oct.2007 9:43:04
                                [kadmin@archangel][~]
                                # cat foo
                                
                                [475] Wed 31.Oct.2007 9:43:06
                                [kadmin@archangel][~]
                                # echo sometext >> foo
                                
                                [476] Wed 31.Oct.2007 9:43:08
                                [kadmin@archangel][~]
                                # cat foo
                                sometext

                                In short, I created a file, showed that it's empty, use the shell to append text to the file, and showed that the text is there. PHP can do the same thing....

                                  never done anything like that before.

                                  i tried it. doesnt seem to write anything to my text file.

                                  <?php 
                                  error_reporting(E_ALL);
                                  $new_array[0] = $_POST['new_no'];
                                  $new_array[1] = $_POST['new_name'];
                                  $myFile = "./job_list.txt";
                                  $new_list = implode("~", $new_array);
                                  $new = "$new_list\n";
                                  system("echo $new >> $myfile");
                                  echo $new;
                                  ?>

                                  edit: thanks for all the help. it is obvious that this will never work correctly for me. so this is my give up point. perhaps i will try something other than writing to a text file.

                                    Hmm, is PHP running in safe mode? (check php.ini).

                                      safe_mode		=	Off

                                      see the attached text file for more info....