Hi,
I am new to PHP and Mysql development .
I had installed RHEL5 Server, Apache, PHP5 and MYSQL5.1.
I got below script which actually give status of the Apache, PHP and MYSQL.

<?php
session_start();
?>

<!-- 
INSTRUCTIONS:
	1. Please copy this file anywhere in the DocumentRoot of your server.
	2. Please change the mysql root user's password on line "mysql_connect".
	3. Access this file through any browser.
-->


<html>
<body>
<?php
Session_register("S_test");

?>

Today is: <?
print date(d."/".m."/".Y) ?>
<table><tr><td bgcolor=#88aadd>
<b>
If you see current date above, it means that:<br>
	1. Apache is UP<br>
	2. PHP is UP<br>
</td></tr></table>
<br>&nbsp;
</b>


Now I will display mysql Users' List:<br>

<?
$sql="select Host, User from user";

$i=0;


# Change your password in the next line: its the 3rd parameter.
$Conn=mysql_connect("localhost","root","root");

$rs=mysql("mysql",$sql);

while ($i < mysql_num_rows($rs)) {
        list($Host, $User)=mysql_fetch_row($rs);
	print ":.........".$Host."&nbsp;.....:......&nbsp;".$User."<br>";

        $i++;
}
$S_test="test";
print $S_test;
?>
<table><tr><td bgcolor=#88aadd>
<b>
If you see at least one line above like "....Host.....User", it means that:<br>
1. The mysql server is UP<br>
2. The mysql server is accessible through PHP<br>
<br>
If you see something like "<font color=red>Warning: MySQL Connection Failed: Access denied for user........</font>", please open myself (i.e. <?=$HTTP_SERVER_VARS["SCRIPT_FILENAME"];?>) and correct password in the function "mysql_connect" and run me again. 
</td></tr></table>

When I try to view this it gives Apache and PHP up but it is not showing list of users as expected neither giving any error message.
When I try to connect to mysql using loging root and password root it get connected but through PHP it is not working.
Is there something which I have missed out?

Thanks in advance.

When I try to view this it gives Apache and PHP up but it is not showing list of users as expected neither giving any error message.
When I try to connect to mysql using loging root and password root it get connected but through PHP it is not working.

If it is not getting connected through php, it will throw an error. Check your php.ini file about error reporting.
If its value is not

error_reporting = E_ALL & ~E_NOTICE

change it. This means, Show all errors except notices.
I tested the script and its fine. But its outdated. Nobody uses session_register nowadays. If you want to register a session variable, you just use $_SESSION = "value";
Quoting from Php.net

Warning
This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

Good luck!

I have checked in php.ini, it contains value as

error_reporting = E_ALL & ~E_NOTICE

So I checked in httpd/error_log file for error. I found following error entry.

Call to undefined function mysql_connect() in /var/www/html/phptest.php on line 31

Am I missing something?

You need to install php-mysql

Type "yum install php-mysql" its needed to get Mysql and php to play together nicely, it includes functions like mysql_connect()

And if you are a windows user, check this link, especially the reply from a user called 'savbill'. :)

He is a linux user

he clearly said "I had installed RHEL5 Server"

I have installed php-mysql and now its working fine.
Thanks.

No problem. Glad you got it solved.

He is a linux user

he clearly said "I had installed RHEL5 Server"

:$ Ah! I clearly missed it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.