Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with MySQL status request

Status
Not open for further replies.

zapcat

Technical User
Feb 13, 2004
2
GB
I'm just learning MySQL & PHP and have been given this code to get a status report on the mysql database on my server. Line 17 (indicated with ***THIS LINE*** below)keeps getting rejected but as I'm new to this I can't figure out why. (PHP version is 4.3.3) Can anyone help?

<html>
<head>
<title>Test MySQL</title>
<body>
<!-- mysql_up.php -->
<?php
$host=&quot;localhost&quot;;
$user=&quot;xxx&quot;;
$password=&quot;xxx&quot;;

mysql_connect($host,$user,$password);
$sql=&quot;show status&quot;;
$result = mysql_query($sql);
if ($result == 0)
echo(&quot;<b>Error &quot; . mysql_errno() . &quot;: &quot; . mysql_error() . &quot;</b>);
elseif (mysql_num_rows($result) == 0)
***THIS LINE***echo(&quot;<b>Query executed successfully!</b>&quot;); ***THIS LINE***
else
{
?>
<!-- Table that displays the results -->
<table border=&quot;1&quot;>
<tr><td><b>Variable_name</b></td><td><b>Value</b></td></tr>
<?php
for ($i = 0; $i < mysql_num_rows($result); $i++ {
echo(&quot;<TR>&quot;);
$row_array = mysql_fetch_row($result);
for ($j = 0; $j < mysql_num_fields($result); $j++) {
echo(&quot;<TD>&quot; . $row_array[$j] . &quot;</td>&quot;);
}
echo(&quot;</tr>&quot;);
}
?>
</table>
<?php } ?>

<!-- ZoneLabs Popup Blocking Insertion -->
<script language='javascript'>postamble();</script>

<!-- ZoneLabs Popup Blocking Insertion -->
<script language='javascript'>postamble();</script>
</body>
</html>
 
Don't you need:

if ($result == 0) {
echo(&quot;<b>Error &quot; . mysql_errno() . &quot;: &quot; . mysql_error() . &quot;</b>);
} elseif (mysql_num_rows($result) == 0) {
***THIS LINE***echo(&quot;<b>Query executed successfully!</b>&quot;); ***THIS LINE***
} else
{
 
Bheath - thanks for the advice, but it didn't work :(

Any other ideas?
 
Seometimes with PHP the line number where the script dies isn't the line where you'll find the error. You're also missing a close-quote at the end of this line:

echo(&quot;<b>Error &quot; . mysql_errno() . &quot;: &quot; . mysql_error() . &quot;</b>);

It should be:

echo(&quot;<b>Error &quot; . mysql_errno() . &quot;: &quot; . mysql_error() . &quot;</b>&quot;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top