Forum Moderators: coopster

Message Too Old, No Replies

Insert Database Info Into HTML Page

insert php into html static page

         

webfirst

7:07 am on Apr 27, 2007 (gmt 0)

10+ Year Member



I think this may be simple, just not for me. I need to know how to insert a php code that pull info from a mysql database into a static html page.

This is not the code but will work for what I need:

<?php

$host="localhost"; // Host name
$username="#*$!x_test"; // Mysql username
$password="#*$!x"; // Mysql password
$db_name="#*$!x_#*$!"; // Database name
$tbl_name="#*$!x_#*$!"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $rows['id'];?></td>
<td width="30%"><? echo $rows['name'];?></td>
<td width="30%"><? echo $rows['lastname'];?></td>
<td width="30%"><? echo $rows['email'];?></td>
</tr>
</table>

<?
// close while loop
}

// close connection
mysql_close();
?>

The only way I have been able to make this information appear in a html page is by creating the code and saving as a .php file and then insertig it into the page via; SSI. The part of the code that I need to show on the html page has been bolded in the code above.

<!--#include virtual="/#*$!xx.php" -->

There has got to be a simple way to do this and I hate being so dumb on this issue, but I've never had to do this before.

If anyone has info on this, pleasssse help.

joelgreen

2:14 pm on Apr 27, 2007 (gmt 0)

10+ Year Member



You could add directive to parse html pages as php

[webmasterworld.com...]

In this case you will be able to insert php directly inside html page

gettopreacherman

4:00 pm on Apr 27, 2007 (gmt 0)

10+ Year Member



Find your .htaccess and add the handler:

AddHandler application/x-httpd-php .php .php3 .html .htm .asp

ksks

4:50 pm on Apr 27, 2007 (gmt 0)

10+ Year Member



"I need to know how to 'insert a php code' that pull info from a mysql database into a 'static html' page."

Sorry, but I think you contradicted yourself...:)
If you mean render a page with "*.html", then use the .htaccess like stated above...

webfirst

9:20 pm on Apr 27, 2007 (gmt 0)

10+ Year Member



Thanks everyone. This is working great.