Aymen++
04-15-2004, 07:16 AM
i wana do one page that displays the connection status or the databases on MySQL depending on the value of a variable (action). i did it like this:
<html>
<head>
<title>Welcome</title>
</head>
<body>
<?php
function disconnect() {
global $r;
mysql_close($r) or die("Could not disconnect: " . mysql_error());
echo "You have been disconnected successfully";
}
switch ($action) {
case "showdatabases":
$db_list = mysql_list_dbs($r);
while($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
break;
case "disconnect":
disconnect();
break;
default:
$conn = mysql_connect($dbhost, $txtUserName, $txtPassword) or die("Could not Connect: " . mysql_error());
echo "Connected successfully<BR>";
echo "<a href='index.php?action=showdatabases&r=$conn'>Show databases<BR></a>";
echo "<a href='index.php?action=disconnect&r=$conn'>Disconnect<BR></a>";
}
?>
</body>
</html>
and i had this error when i press show databases:
Warning: Supplied argument is not a valid MySQL-Link resource in c:\program files\apache group\apache\htdocs\test\index.php on line 17
Warning: Supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\test\index.php on line 18
and this when i press disconnect:
Warning: Supplied argument is not a valid MySQL-Link resource in c:\program files\apache group\apache\htdocs\test\index.php on line 11
Could not disconnect:
so, how can i pass the value of $conn to another page?
<html>
<head>
<title>Welcome</title>
</head>
<body>
<?php
function disconnect() {
global $r;
mysql_close($r) or die("Could not disconnect: " . mysql_error());
echo "You have been disconnected successfully";
}
switch ($action) {
case "showdatabases":
$db_list = mysql_list_dbs($r);
while($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
break;
case "disconnect":
disconnect();
break;
default:
$conn = mysql_connect($dbhost, $txtUserName, $txtPassword) or die("Could not Connect: " . mysql_error());
echo "Connected successfully<BR>";
echo "<a href='index.php?action=showdatabases&r=$conn'>Show databases<BR></a>";
echo "<a href='index.php?action=disconnect&r=$conn'>Disconnect<BR></a>";
}
?>
</body>
</html>
and i had this error when i press show databases:
Warning: Supplied argument is not a valid MySQL-Link resource in c:\program files\apache group\apache\htdocs\test\index.php on line 17
Warning: Supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\test\index.php on line 18
and this when i press disconnect:
Warning: Supplied argument is not a valid MySQL-Link resource in c:\program files\apache group\apache\htdocs\test\index.php on line 11
Could not disconnect:
so, how can i pass the value of $conn to another page?