Connecting Tech Pros Worldwide Help | Site Map

HTML form failing when using PHP include function

Newbie
 
Join Date: Jul 2009
Posts: 5
#1: Jul 30 '09
Hi,

I'm trying to create a dynamic form that is accessed from multiple pages. I've created the form and included into one of the main PHP pages using the include() function.

Now, when I run the form, it seems to be ignoring the <form> tag entirely. I want the form to pass the data to another PHP script for validation and dumping into the database. The form will only pass the details back to same page the form is run from.

The form works as it should when I run it's script individually, but not through another page using include().

Any suggestions or help would be great appreciated. Thanks in advance,

Vladimir
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#2: Jul 30 '09

re: HTML form failing when using PHP include function


View your source in your browse and see the HTML is what you expect.


Dan
Newbie
 
Join Date: Jul 2009
Posts: 5
#3: Aug 5 '09

re: HTML form failing when using PHP include function


Hi Dan,

Thanks for the speedy reply.

I've had another play with it and decided to strip it down to it's basic form. I added in an identical form into the index.php script. The HTML is echoing out correctly and appears correct in view source.

The form will still not move to another page.

Vladimir
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: Aug 5 '09

re: HTML form failing when using PHP include function


We're going to have to see the source code, HTML and PHP, if we're going to help you.
Newbie
 
Join Date: Jul 2009
Posts: 5
#5: Aug 5 '09

re: HTML form failing when using PHP include function


Hi Markus,

Thanks for the reply. The code I'm using for the Index.php script is posted below.
Do you also require the output HTML from the view source?

Thanks,

Vladimir

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //Database connection data
  4. include("config/db_config.php");
  5. opendb($dbhost, $dbuser, $dbpass, $dbname);
  6.  
  7. $pagetitle = "Asset Catalogue Front Page";
  8.  
  9. //HTML header information. Assigns variable $pagetitle as the title for the page
  10. include("layout/htmlheader.php");
  11.  
  12.  
  13. //checks for previously run forms/**/
  14. //$delete = $_POST['delete'];
  15. //if(isset($delete))
  16. //  {
  17.     //script to delete the selected entry from the database
  18. //    include("data/delete.php");
  19. //  }
  20.  
  21.  
  22. //Table data for the main output
  23. echo ("<table border=1>");
  24. echo ("<tr name=\"title\">");
  25. echo ("<td>Field</td>");
  26. echo ("<td>Field</td>");
  27. echo ("<td>Field</td>");
  28. echo ("<td>Field</td>");
  29. echo ("<td>Field</td>");
  30. echo ("<td>Field</td>");
  31. echo ("<td>Field</td>");
  32. echo ("<td>Field</td>");
  33. echo ("<td>Field</td>");
  34. echo ("<td>Delete</td>");
  35. echo ("</tr>");
  36.  
  37. //script to pull data from database, assign to variable and echo into table
  38. include("data/select.php");
  39.  
  40. echo ("</table>");
  41.  
  42. //Form for inputting a new record
  43.  
  44. $rows = 1;
  45.  
  46. echo ("</br>");
  47. echo ("<table border =1>");
  48. echo ("<tr>");
  49. echo ("<td>");
  50. echo ("Field");
  51. echo ("</td>");
  52. echo ("<td>");
  53. echo ("Field");
  54. echo ("</td>");
  55. echo ("<td>");
  56. echo ("Field");
  57. echo ("</td>");
  58. echo ("<td>");
  59. echo ("Field");
  60. echo ("</td>");
  61. echo ("<td>");
  62. echo ("Field");
  63. echo ("</td>");
  64. echo ("<td>");
  65. echo ("Field");
  66. echo ("</td>");
  67. echo ("<td>");
  68. echo ("Field");
  69. echo ("</td>");
  70. echo ("<td>");
  71. echo ("Field");
  72. echo ("</td>");
  73. echo ("<td>");
  74. echo ("Field");
  75. echo ("</td>");
  76. echo ("</tr>");
  77.  
  78.  
  79.  
  80. echo ("<form action=\"insert.php\" method=\"POST\" >");
  81. echo ("<input type=\"submit\" name=\"submit\">");
  82. echo ("</form>");
  83.  
  84.  
  85. echo ("</table>");
  86.  
  87. //HTML footer information
  88. include("layout/htmlfooter.php");
  89.  
  90.  
  91.  
  92. ?> 
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: Aug 5 '09

re: HTML form failing when using PHP include function


Yes please - the HTML source would be useful.

Is the form that is not working, the one located ~line #80?

Also, doing all that echo()ing isn't the best way to achieve that result - have a look at the heredoc syntax.

Mark.
Newbie
 
Join Date: Jul 2009
Posts: 5
#7: Aug 5 '09

re: HTML form failing when using PHP include function


Thanks for telling me about the heredoc syntax. Very useful!
I'll start using that from now on.

Anyhow; It is the form at line 80 that is the problem. I removed all the form fields to test the form.
Also, here is the HTML from view source:



Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Title</title>
  4. </head>
  5. <body> 
  6. <table border=1>
  7. <tr name="field">
  8. <td>Field</td>
  9. <td>Field</td>
  10. <td>Field</td>
  11. <td>Field</td>
  12. <td>Field</td>
  13. <td>Field</td>
  14. <td>Field</td>
  15. <td>Field</td>
  16. <td>Field</td>
  17. <td>Field</td>
  18. </tr>
  19. <tr name="Field">
  20. <td>123</td>
  21. <td>123</td>
  22. <td>123</td>
  23. <td>123</td>
  24. <td>123</td>
  25. <td>123</td>
  26. <td>123-2009</td>
  27. <td>123</td>
  28. <td>2009-08-05 09:07:27</td>
  29. <td><form method="POST"><input type="hidden" name="id" value="123"><input type="submit" name="delete" value="Delete"></td>
  30. </tr>
  31. </table>
  32.  
  33.  
  34. <table border =1>
  35. <tr>
  36. <td>Field</td>
  37. <td>Field</td>
  38. <td>Field</td>
  39. <td>Field</td>
  40. <td>Field</td>
  41. <td>Field</td>
  42. <td>Field</td>
  43. <td>Field</td>
  44. <td>Field</td>
  45. </tr>
  46. <form action="insert.php" method="POST" ><input type="submit" name="submit"></form>
  47.  
  48. </table>
  49. </body>
  50. </html> 
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#8: Aug 5 '09

re: HTML form failing when using PHP include function


Close the form on line 29.

Mark.
Newbie
 
Join Date: Jul 2009
Posts: 5
#9: Aug 5 '09

re: HTML form failing when using PHP include function


Thanks Mark,

Not sure how I missed that. Think it's a case of can't see the forest for the trees.
Thanks a lot.

Vladimir.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#10: Aug 5 '09

re: HTML form failing when using PHP include function


Quote:

Originally Posted by vladimirblotan View Post

Thanks Mark,

Not sure how I missed that. Think it's a case of can't see the forest for the trees.
Thanks a lot.

Vladimir.

No problem, Vladimir.

Easy mistake :)
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#11: Aug 5 '09

re: HTML form failing when using PHP include function


Quote:

Originally Posted by dlite922 View Post

View your source in your browse and see the HTML is what you expect.


Dan

Yes, My reply was very general, but it was as simple as pasting the HTML source into this: http://validator.w3.org

BAM! problem found in 2 seconds :)



Dan
Reply

Tags
form, html, include, php


Similar PHP bytes