HTML form failing when using PHP include function | Newbie | | Join Date: Jul 2009
Posts: 5
| | |
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
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,094
| | | 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
| | | 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
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | 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
| | | 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 - <?php
-
-
//Database connection data
-
include("config/db_config.php");
-
opendb($dbhost, $dbuser, $dbpass, $dbname);
-
-
$pagetitle = "Asset Catalogue Front Page";
-
-
//HTML header information. Assigns variable $pagetitle as the title for the page
-
include("layout/htmlheader.php");
-
-
-
//checks for previously run forms/**/
-
//$delete = $_POST['delete'];
-
//if(isset($delete))
-
// {
-
//script to delete the selected entry from the database
-
// include("data/delete.php");
-
// }
-
-
-
//Table data for the main output
-
echo ("<table border=1>");
-
echo ("<tr name=\"title\">");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Field</td>");
-
echo ("<td>Delete</td>");
-
echo ("</tr>");
-
-
//script to pull data from database, assign to variable and echo into table
-
include("data/select.php");
-
-
echo ("</table>");
-
-
//Form for inputting a new record
-
-
$rows = 1;
-
-
echo ("</br>");
-
echo ("<table border =1>");
-
echo ("<tr>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("<td>");
-
echo ("Field");
-
echo ("</td>");
-
echo ("</tr>");
-
-
-
-
echo ("<form action=\"insert.php\" method=\"POST\" >");
-
echo ("<input type=\"submit\" name=\"submit\">");
-
echo ("</form>");
-
-
-
echo ("</table>");
-
-
//HTML footer information
-
include("layout/htmlfooter.php");
-
-
-
-
?>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | 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
| | | 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: - <html>
-
<head>
-
<title>Title</title>
-
</head>
-
<body>
-
<table border=1>
-
<tr name="field">
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
</tr>
-
<tr name="Field">
-
<td>123</td>
-
<td>123</td>
-
<td>123</td>
-
<td>123</td>
-
<td>123</td>
-
<td>123</td>
-
<td>123-2009</td>
-
<td>123</td>
-
<td>2009-08-05 09:07:27</td>
-
<td><form method="POST"><input type="hidden" name="id" value="123"><input type="submit" name="delete" value="Delete"></td>
-
</tr>
-
</table>
-
-
-
<table border =1>
-
<tr>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
<td>Field</td>
-
</tr>
-
<form action="insert.php" method="POST" ><input type="submit" name="submit"></form>
-
-
</table>
-
</body>
-
</html>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: HTML form failing when using PHP include function
Close the form on line 29.
Mark.
| | Newbie | | Join Date: Jul 2009
Posts: 5
| | | 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.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: HTML form failing when using PHP include function Quote:
Originally Posted by vladimirblotan 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 :)
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,094
| | | re: HTML form failing when using PHP include function Quote:
Originally Posted by dlite922 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
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|