php doc working but same php script in html doc not working

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php doc working but same php script in html doc not working

Postby paddyhughes086 » 19. October 2012 22:15

Hi I have php code and it works when I save it as say test1.php it runs and looks in the database and prints out my info.
But if I put the same code into a html DOC e.g test2.html the php does not run at all... now this is not that important but i am just wondering why this is happening as when i run it on www.000webhost.com. it doesn’t matter what i have it saved as e.g .php or .html as long as I have all the tags correct. why is XAMPP FOR WINDOWS not the same


Code: Select all
<?php
error_reporting(E_ALL);

// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "datab";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "root";
$db_word = "password";

// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB CONNECTION: ";
    echo "<br/> $errmsg <br/>";
}

// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB SELECTION: ";
    echo "<br/> $errmsg <br/>";
    die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES

// GET THE LIST OF TABLES
$sql = "SHOW TABLES";
$res = mysql_query($sql) or die("FAIL: $sql <br/>" . mysql_error() );

// CREATE AN ARRAY OF TABLE NAMES
$tables = array();
while ($row = mysql_fetch_array($res))
{
    $tables[] = $row[0];
}

// GET THE COUNT OF TABLES
$total = count($tables);

// TEST EACH TABLE FOR ROWS OF DATA
$used = 0;
foreach ($tables as $table)
{
     if ($table!="class" && $table!="room" && $table!="student" && $table!="subject" && $table!="teacher" && $table!="users") {
         $sql = "SELECT * FROM $table LIMIT 1";
         $res = mysql_query($sql) or die("FAIL: $sql <br/>" . mysql_error() );
         $num = mysql_num_rows($res);
         if ($num) $used++;
     }


// SHOW THE WORK PRODUCT
echo "THERE ARE $total TABLES, AND THERE ARE $used WITH DATA";
?>

paddyhughes086
 
Posts: 2
Joined: 19. October 2012 22:03
Operating System: win 7

Re: php doc working but same php script in html doc not work

Postby Altrea » 19. October 2012 22:23

Hi paddyhughes086,

paddyhughes086 wrote:i am just wondering why this is happening as when i run it on http://www.000webhost.com. it doesn’t matter what i have it saved as e.g .php or .html as long as I have all the tags correct. why is XAMPP FOR WINDOWS not the same

000webhost uses a different configuration. Their HTTP Daemon is configurated to send all html and php files (and maybe many other filetypes) through the php interpreter first. In most cases this just slow down the response to the browser, because it is not that common to place .php code in other filetypes. That's why XAMPP don't uses that type of configuration.

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: php doc working but same php script in html doc not work

Postby paddyhughes086 » 19. October 2012 22:27

Altrea wrote:Hi paddyhughes086,

paddyhughes086 wrote:i am just wondering why this is happening as when i run it on http://www.000webhost.com. it doesn’t matter what i have it saved as e.g .php or .html as long as I have all the tags correct. why is XAMPP FOR WINDOWS not the same

000webhost uses a different configuration. Their HTTP Daemon is configurated to send all html and php files (and maybe many other filetypes) through the php interpreter first. In most cases this just slow down the response to the browser, because it is not that common to place .php code in other filetypes. That's why XAMPP don't uses that type of configuration.

best wishes,
Altrea


Thanks for the quick reply and simple answer
paddyhughes086
 
Posts: 2
Joined: 19. October 2012 22:03
Operating System: win 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 107 guests