Sunday 15 July 2012

Display PHP inside of an HTML page -



Display PHP inside of an HTML page -

i'd query mysql database single field ["notice"] , display result in shtml page. query never homecoming more 1 row , returns 1 column. if there's in row, i'd show text , <br>. if select statement returns nothing, i'd display nothing, not <br>. have next code works fine test when it's saved php file. however, if re-create within <body> tags , insert html page body, lastly half of code displayed. displays after greater symbol in if statement text. similarly, if save code html or shtml file instead of php file, display lastly half of code in browser. how include <body> tag on html page?

thanks looking @ this.

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> <?php $servername = "localhost"; $username = "myusername"; $password = "mypassword"; $dbname = "mydbname"; // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$conn) { die("connection failed: " . mysqli_connect_error()); } $sql = "select notice notification page = 'home'"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output info of each row while($row = mysqli_fetch_assoc($result)) { echo "message is: " . $row["notice"]. "<br>"; } } else { echo "0 results"; } mysqli_close($conn); ?> </body> </html>

you'll need utilize .htaccess run file through php parser. similar to:

<filesmatch "\.(htm|html|shtm|shtml)$"> sethandler application/x-httpd-php5 </filesmatch>

php html

No comments:

Post a Comment