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";
?>