<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and outputs settings.
* Testing Mysql -- page 35
*/
// Starting page generation
echo "<html>
<head><title>test MySQL</title></head>
<body>\n";
// SQL Credentials
$database = "database";
$host = "host";
$user = "mysqlaccount";
$password = "mysqlpassword";
// Connecting to the database
$cxn = mysql_connect($host, $user, $password);
$sql = "SHOW GLOBAL STATUS";
$result = mysql_query($sql, $cxn);
// Checking for errors
if($result == false)
{
echo "<h4>error: " . mysql_error($cxn) . "</h4>";
}
else
{
//* Displaying the table
echo "<table border='1'>
<tr><th>variable_name</th></tr>\n";
for($i = 0; $i < mysql_num_rows($result); $i++)
{
echo "<tr>\n";
$row_array = mysql_fetch_row($result);
for($j = 0; $j < mysql_num_fields($result); $j++)
{
echo "<td>{$row_array[$j]}</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
}
?>
</body></html>
- <?php
- /* Program: mysql_up.php
- * Desc: Connects to MySQL Server and outputs settings.
- * Testing Mysql -- page 35
- */
-
- // Starting page generation
- echo "<html>
- <head><title>test MySQL</title></head>
- <body>\n";
-
- // SQL Credentials
- $database = "database";
- $host = "host";
- $user = "mysqlaccount";
- $password = "mysqlpassword";
-
- // Connecting to the database
- $cxn = mysql_connect($host, $user, $password);
- $sql = "SHOW GLOBAL STATUS";
- $result = mysql_query($sql, $cxn);
-
- // Checking for errors
- if($result == false)
- {
- echo "<h4>error: " . mysql_error($cxn) . "</h4>";
- }
- else
- {
-
- //* Displaying the table
- echo "<table border='1'>
- <tr><th>variable_name</th></tr>\n";
- for($i = 0; $i < mysql_num_rows($result); $i++)
- {
- echo "<tr>\n";
- $row_array = mysql_fetch_row($result);
- for($j = 0; $j < mysql_num_fields($result); $j++)
- {
- echo "<td>{$row_array[$j]}</td>\n";
- }
- echo "</tr>\n";
- }
- echo "</table>";
- }
- ?>
- </body></html>
All it was was spelling errors in functions and a boolean. A few missing dollar signs ($) that indicates a variable... a misplaced </tr>...
I even formatted the code for you

Here, instead of just giving you the fixed code, I'll run you through the code you posted and tell you exactly where you went wrong
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and outputs settings.
* Testing Mysql -- page 35
*/
echo "<html>
<head> <title>test MySQL</title></head>
<body>";
$database = "database";
$mysql_user = "mysqluser";
$password = "mysqlpassowrd";
$host="host";
$user="mysqlaccount";
$password="mysqlpasssowrd";
- <?php
- /* Program: mysql_up.php
- * Desc: Connects to MySQL Server and outputs settings.
- * Testing Mysql -- page 35
- */
- echo "<html>
- <head> <title>test MySQL</title></head>
- <body>";
- $database = "database";
- $mysql_user = "mysqluser";
- $password = "mysqlpassowrd";
- $host="host";
- $user="mysqlaccount";
- $password="mysqlpasssowrd";
That has nothing bad in it... maybe could be formatted a bit better. The only thing I see there is that you got two password variables in there ($password)
$cxn = mysqli_connect($host, $user. $password);
$sql ="SHOW GLOBAL STATUS";
$result = mysql_query ($cxn,$sql);
- $cxn = mysqli_connect($host, $user. $password);
- $sql ="SHOW GLOBAL STATUS";
- $result = mysql_query ($cxn,$sql);
You are using mysql
i_connect but mysql_query... remove that "i" from mysqli_connect and you should be good.
Another thing... you put the link identifier ($cxn) first... contrary to what you put there, the $sql should be the first argument passed into mysql_query (mysql(
$sql, $cxn))
That is supposed to be
false... not
flase
echo "<h4>error: ".mysqli_eror(cxn)."</h4>";
}
- echo "<h4>error: ".mysqli_eror(cxn)."</h4>";
- }
Here is one place where you missed the dollar sign... that
cxn is supposed to be
$cxn
else
{
//* Table that displays
echo "<table border='1'>
<tr><th>variable_name</tr>";
- else
- {
- //* Table that displays
-
- echo "<table border='1'>
- <tr><th>variable_name</tr>";
You are missing a </th> right before that </tr> (Wouldn't throw a PHP error... the HTML might look funky though.
for($i = 0; $i < mydwli_num_rows($result); $i++)
{
- for($i = 0; $i < mydwli_num_rows($result); $i++)
- {
I've never heard of a mydwli_num_rows function... unless you declared that function somewhere, it's supposed to be
mysql_num_rows Probably typing too fast
echo "<tr>";
$row_array = mysqli_fetch_row($result);
for($j = 0;$j < mysqli_num_feilds($result);$j++)
{
- echo "<tr>";
- $row_array = mysqli_fetch_row($result);
- for($j = 0;$j < mysqli_num_feilds($result);$j++)
- {
Those
mysqli_* should be
mysql_* (mysql_fetch_row($result) and mysql_num_fields($result)
You also misspelled fields... you spelled it feilds. Typing too fast again (I think).
echo "<td>".row_array[$j]."</td>\n";
}
}
echo "</table>";
}
?>
</body></html>
- echo "<td>".row_array[$j]."</td>\n";
- }
-
- }
- echo "</table>";
- }
- ?>
- </body></html>
Another instance where you forgot that dollar sign... that
row_array[$j] should have a dollar sign right in front of it. So it should be
$row_array[$j] ... the fact that the variable is an array doesn't change anything.
That line could be typed a bit better too... using curly brackets.
echo "<td>{$row_array[$j]}</td>\n";
That saves some space
