action not working after submitting form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpnewbie26
    New Member
    • Jun 2009
    • 52

    action not working after submitting form

    This has been confusing me for a while. I don't understand why it isn't working. In my original coding, I have an action called submitted.php and this is what is looks like:

    Code:
    <?php 
    $data=fopen("/home/vchan/ts2/writing.txt","r+");
    while(!feof($data)){
    $data2=fgets($data);
    $tmp=explode(",",$data2);
    $project=$tmp[0];
    $code=$tmp[1];
    $realname=$tmp[2];
    $counter=$tmp[3];
    $dateentry=$tmp[4];
    $name=$tmp[5];
    $hours=$tmp[6];
    $description=$tmp[7];
    echo '$name';
    }
    fclose($data);
    
    ?>
    <html>
    <body>
    <?php
    echo 'Thank you for submitting. <br> To submit another, please click here.';
    ?>
    </body>
    </html>
    <?php
    echo '<form action="test5.php" method="post"> ';
    echo'<p><input type="submit" value="Submit Another"/></p>';
    echo '</form>';
    ?>
    This isn't the full code but my problem is that it doesn't do anything after I open that first file hence it doesnt print "name". But oddly, it prints all the things in the end: "Thank you for submitting..."w hich is not related to the opening of the file. Any help would be greatly appreciated.><
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by phpnewbie26
    my problem is that it doesn't do anything after I open that first file hence it doesnt print "name".
    have you checked the source code? you print the name where you're not supposed to get any visible output (i.e. outside the html page, which essentially renders your document invalid).

    put your php code inside the html body.

    one more, you should also don't print anything after </html> (the end of the html page)

    and you should use a DTD to put IE in standards mode

    Comment

    • phpnewbie26
      New Member
      • Jun 2009
      • 52

      #3
      i put it inside the html body and it still doesnt work..=/ and whats a DTD?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by phpnewbie26
        i put it inside the html body and it still doesnt work..=/
        post your code (and maybe the file), maybe I can see anything.

        Originally posted by phpnewbie26
        and whats a DTD?
        a document type definition. see XHTML and HTML specification

        Comment

        • phpnewbie26
          New Member
          • Jun 2009
          • 52

          #5
          Okay..well, it seems that I didnt save it in the right folder, but now arises the actual problem. The first line, I changed it to
          Code:
          $data=fopen("/home/$_POST["name"]/ts2/writing.txt","r+");
          My problem is that in my original coding, I type my "name" in another form which is not the same as where my action="submitt ed.php" is. I was wondering if there is a way to carry over variables like that. I don't know if I explained myself properly.=/

          Comment

          • phpnewbie26
            New Member
            • Jun 2009
            • 52

            #6
            So I actually got it to work by using sessions. Thanks for all the help.=D

            Comment

            • smithroy9
              New Member
              • Apr 2009
              • 3

              #7
              Thanks for solving my problem.
              Last edited by Atli; Jun 18 '09, 05:44 PM. Reason: Advertisement removed.

              Comment

              Working...