Connecting Tech Pros Worldwide Forums | Help | Site Map

action not working after submitting form

Member
 
Join Date: Jun 2009
Posts: 52
#1: Jun 11 '09
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:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $data=fopen("/home/vchan/ts2/writing.txt","r+");
  3. while(!feof($data)){
  4. $data2=fgets($data);
  5. $tmp=explode(",",$data2);
  6. $project=$tmp[0];
  7. $code=$tmp[1];
  8. $realname=$tmp[2];
  9. $counter=$tmp[3];
  10. $dateentry=$tmp[4];
  11. $name=$tmp[5];
  12. $hours=$tmp[6];
  13. $description=$tmp[7];
  14. echo '$name';
  15. }
  16. fclose($data);
  17.  
  18. ?>
  19. <html>
  20. <body>
  21. <?php
  22. echo 'Thank you for submitting. <br> To submit another, please click here.';
  23. ?>
  24. </body>
  25. </html>
  26. <?php
  27. echo '<form action="test5.php" method="post"> ';
  28. echo'<p><input type="submit" value="Submit Another"/></p>';
  29. echo '</form>';
  30. ?>
  31.  
  32.  
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..."which is not related to the opening of the file. Any help would be greatly appreciated.><

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#2: Jun 11 '09

re: action not working after submitting form


Quote:

Originally Posted by phpnewbie26 View Post

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
Member
 
Join Date: Jun 2009
Posts: 52
#3: Jun 11 '09

re: action not working after submitting form


i put it inside the html body and it still doesnt work..=/ and whats a DTD?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#4: Jun 11 '09

re: action not working after submitting form


Quote:

Originally Posted by phpnewbie26 View Post

i put it inside the html body and it still doesnt work..=/

post your code (and maybe the file), maybe I can see anything.

Quote:

Originally Posted by phpnewbie26 View Post

and whats a DTD?

a document type definition. see XHTML and HTML specification
Member
 
Join Date: Jun 2009
Posts: 52
#5: Jun 12 '09

re: action not working after submitting form


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
Expand|Select|Wrap|Line Numbers
  1. $data=fopen("/home/$_POST["name"]/ts2/writing.txt","r+");
  2.  
My problem is that in my original coding, I type my "name" in another form which is not the same as where my action="submitted.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.=/
Member
 
Join Date: Jun 2009
Posts: 52
#6: Jun 12 '09

re: action not working after submitting form


So I actually got it to work by using sessions. Thanks for all the help.=D
Newbie
 
Join Date: Apr 2009
Posts: 3
#7: Jun 18 '09

re: action not working after submitting form


Thanks for solving my problem.
Reply