I am trying to send results to a new page.The results are fine.
i.e. once the form is submitted and all input validated I want the result to appear on the results.html page.
I have been able to display the results.html but no data displayed.
I attach some relevant code:

<?php 
if (isset($_POST['name'])) $name = $_POST ['name'];
else $name = "(Not entered)";
echo <<<_END
<html>
	<body>		
	<form method="post" action="working.php">
		Enter Ship Name
		<input type="text" name="name" size="25" maxlength ="35" />
		<input type="image" name="submit" src="newindex_files/cooltext497898955.png" onmouseover="this.src='images/cooltext497898955MouseOver.png';" onmouseout="this.src='images/cooltext497898955.png';" alt="search"/>
	</form>	
	</body>
	</html>
_END;
// [B]placed here 'header' changes page to results.html, but no data displayed[/B]
if($name == "")
{
echo "<p><font color='red' size='4px'>You have not entered a name</font></p>";
exit;
}
else 
{
echo "<p><font color='blue' size='4px'>You searched for: $name</font></p>";
}
require_once 'dbconnect.php';
 // [B]placed here 'header'  changes page to results.html but no data displayed[/B]
$query = "SELECT * FROM allnames WHERE name1 LIKE '$name%' OR name2 LIKE '$name%' OR name3 LIKE '$name%' OR name4 LIKE '$name%' OR name5 LIKE '$name%' OR name6 LIKE '$name%' OR name7 LIKE '$name%' OR name8 LIKE '$name%' OR name9 LIKE '$name%' OR name10 LIKE '$name%' OR name11 LIKE '$name%' OR name12 LIKE '$name%'";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$rows=mysql_num_rows($result);
 //[B]header("Location:http://localhost/wsru/results.html");// placed here 'header'  changes page to results.html[/B]
if(mysql_num_rows($result)==0)
{
echo "No data found for your request. Try a different query.";
exit;
//[B]placed beyond here here 'header' does not work at all.Only 'working.php' details shown.[/B]
}
for ($j=0; $j < $rows ; ++$j)
{
$row =mysql_fetch_row($result);

Am I on the right lines, or is a there a CORRECT way?

Recommended Answers

All 6 Replies

Member Avatar for diafol

html pages can't display php unless you stipulate this in .htaccess. Change .html to .php and it should work (if your code is OK).

html pages can't display php unless you stipulate this in .htaccess. Change .html to .php and it should work (if your code is OK).

I just tested code blow and it didn't work!

<html>
<head> </head>
<body>
<?php echo "It works!"; ?>
</body>
<html>

adding this line in htaccess file worked:

AddType application/x-httpd-php .html .htm

Thank you for the advice. My ISP is not happy for .htaccess to be amended.
However, I have incorporated html coding for my website's logo between
echo<<<_END and echo _END: in the .php code
and this produces an acceptable page display above the results tables.

Member Avatar for diafol

You can't change the file extension of html to php? THat would be a simple solution.

Thank you ardav for your suggestion, but I have struggled to make it work. There must be more to it than that - beyond what I have learned so far.

the test code you posted above is to simple to fail. change the extension!
I'm curious, why would you not change the extension? you are trying to force the html page to do something it was never meant to do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.