SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    my script won't submit anything

    Can anyone see what i'm doing wrong?
    I keep getting a notice about an undefined index for the submit button
    and the script wont add to the .dat file:
    Also, the code that checks if the fields have been filled doesnt seem to be working.


    PHP Code:
    <? if ($_POST["submit"])
     {
       if (
    $_POST["name"] == "")
         echo 
    "Error: No name given.";
       else if (
    $_POST["text"] == "")
         echo 
    "Error: No message.";
       else
       {
         if ((
    $file2 fopen("gb.dat""a")) === FALSE)
           echo 
    "oops";
         else
         {
    $name $_POST["name"];
    $name strip_tags($name);

    $mail $_POST["mail"];
    $mail strip_tags($mail);

    $text $_POST["text"];
    $text strip_tags($text);
           
    $text str_replace("\n",$text);

           
    fwrite($file2time() . "\n");
           
    fwrite($file2$name "\n");
           
    fwrite($file2$mail "\n");
           
    fwrite($file2$text "\n");

           
    fclose ($file2);
         }
       }
     }

     
    $file file("gb.dat");

     
    $lines 0;

     if (
    $file)
       
    $lines count($file)-1;

     if (
    $lines)
       for (
    $i $lines$i 0$i-=4)
       {
         
    $time $file$i ];
         
    $name $file$i ];
         
    $mail $file$i ];
         
    $text $file$i     ];

        echo 
    '

  2. #2
    SitePoint Addict greg76's Avatar
    Join Date
    Aug 2004
    Location
    Poland
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you send files.
    make sure, that your form BEFORE sending anything Can sends files:
    <form method="post" enctype="multipart/form-data">

    and that is includes Mulitpart part.

    G.

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, i tried it, nothing happens.
    but i'm not trying to send files, i'm only trying to add text to a file.
    and then retrieve that information.

  4. #4
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  5. #5
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you the case correct for submit?

    Post the form code too.
    Lats...

  6. #6
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK.
    It's a bit messy cause i used tables for structuring.

    HTML Code:
    <form action="gb.php" method="post" name="f" enctype="multipart/form-data"> 
                <table width="100%"  border="0">
                  <tr>
                    <td class="style2">name:</td>
                    <td class="style1"><input name="name" type="text" class="style1" value="" size="30"></td>
                  </tr>
                  <tr>
                    <td class="style2">e-mail:</td>
                    <td class="style1"><input name="mail" type="text" class="style1" size="30"></td>
                  </tr>
                  <tr>
                    <td valign="top" class="style2">message:</td>
                    <td class="style1"><textarea name="text" cols="44" rows="4" class="style1"></textarea></td>
                  </tr>
                  <tr>
                    <td height="27">&nbsp;</td>
                    <td><input name="submit" type="submit" class="style2" value="speak."></td>
                  </tr>
                </table>
             </form>

  7. #7
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line is incorrect...
    PHP Code:
    $text str_replace("\n",$text); 
    Once that was changed to...
    PHP Code:
    $text str_replace("\n","newline",$text); 
    it ran fine - change 'newline' of course.

    Strange how you received that other error message.
    Lats...

  8. #8
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, wierd.
    nothing happens here..
    i wish i could upload it to a working webserver instead of testing it on stupid IIS. then you could see what i'm talking about.

    it seems like it reloads the page and extracts the info from the datfile, but no new info has been written to it.

    i even tried removing parts of the code to see if it mattered but it didn't

    like this:

    PHP Code:
    //$name = $_POST["name"];
    //    $name = strip_tags($name);

    //    $mail = $_POST["mail"];
    //    $mail = strip_tags($mail);

    //    $text = $_POST["text"];
    //    $text = strip_tags($text);
    //        $text = str_replace("\n","newline",$text);

    //        fwrite($file2, time() . "\n");
    //        fwrite($file2, $name . "\n");
    //        fwrite($file2, $mail . "\n");
    //        fwrite($file2, $text . "\n");

    //        fclose ($file2); 
    it totally ignored it, no error message at all.

  9. #9
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the exact code I just ran, I commented out the reading bits as that doesn't seem to be part of the problem. It appends data as expected...
    PHP Code:
    <? 
    if ($_POST["submit"]) 

       if (
    $_POST["name"] == ""
         echo 
    "Error: No name given."
       else if (
    $_POST["text"] == ""
         echo 
    "Error: No message."
       else 
       { 
         if ((
    $file2 fopen("gb.dat""a")) === FALSE
           echo 
    "oops"
         else 
         { 
    $name $_POST["name"]; 
    $name strip_tags($name); 

    $mail $_POST["mail"]; 
    $mail strip_tags($mail); 

    $text $_POST["text"]; 
    $text strip_tags($text); 
           
    $text str_replace("\n","newline",$text); 

           
    fwrite($file2time() . "\n"); 
           
    fwrite($file2$name "\n"); 
           
    fwrite($file2$mail "\n"); 
           
    fwrite($file2$text "\n"); 

           
    fclose ($file2); 
         } 
       } 


    //$file = file("gb.dat"); 
    //
    //$lines = 0; 
    //
    //if ($file) 
    //   $lines = count($file)-1; 
    //
    //if ($lines) 
    //   for ($i = $lines; $i > 0; $i-=4) 
    //   { 
    //     $time = $file[ $i - 3 ]; 
    //     $name = $file[ $i - 2 ]; 
    //     $mail = $file[ $i - 1 ]; 
    //     $text = $file[ $i     ]; 
    //    }
    //

    ?>

                <form action="writefile.php" method="post" name="f" enctype="multipart/form-data"> 
                <table width="100%"  border="0">
                  <tr>
                    <td class="style2">name:</td>
                    <td class="style1"><input name="name" type="text" class="style1" value="" size="30"></td>
                  </tr>
                  <tr>
                    <td class="style2">e-mail:</td>
                    <td class="style1"><input name="mail" type="text" class="style1" size="30"></td>
                  </tr>
                  <tr>
                    <td valign="top" class="style2">message:</td>
                    <td class="style1"><textarea name="text" cols="44" rows="4" class="style1"></textarea></td>
                  </tr>
                  <tr>
                    <td height="27">&nbsp;</td>
                    <td><input name="submit" type="submit" class="style2" value="speak."></td>
                  </tr>
                </table>
             </form>
    Lats...

  10. #10
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The files is saved as writefile.php as shown in the form code.
    Lats...

  11. #11
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried recreating the page with the code you posted and then
    i checked the gb.dat file after executing the form, and nothing new was there.

    sorry for being such a nusaunce to you..

  12. #12
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess the script does not have write permission - are you able to adjust that yourself?

    For local testing, I find XAMPP to be really helpful, check it out...

    http://www.apachefriends.org/en/xampp.html
    Lats...

  13. #13
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh but it has, i made sure the entire site had that just for testing.

    are you sure the code for writing into the gb.dat file is correct?

  14. #14
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, data is being appended just fine here.
    Lats...

  15. #15
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there anything else i might have missed?
    like php.ini settings or something?

  16. #16
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll have to pass on that one, sorry.

    The only problems I've had in the past, at work, is where the admin needed to set write permissions on scripts written for our intranet.
    Lats...

  17. #17
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's allright.
    thanks for all your help anyway!

    i'll poke some more at it to see if i can find the problem.
    nice to know it's not the code.

    thanks again.

  18. #18
    SitePoint Member
    Join Date
    Dec 2004
    Location
    sweden
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now i'm very very confused.
    updated just one last time for the heck of it, and now it seems to work just fine.

    i better go to sleep cause now i think the comp is playing tricks on me...

  19. #19
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, I've seen that happen a few times
    Lats...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •