Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource
This is the code where I am constantly getting an error. The same include file works on the other pages, I am only getting problem on this page. Here is the error
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/html/spywgc/adm/ctshell/getproduct/getproduct.php on line 18
And here开发者_JAVA百科 is the actual code :
<?php require_once('../../../Connections/spyware_adm.php'); ?>
<?php require_once('../../../includes/lib_gen.php'); ?>
<?php
//function for returing status of website
function Visit($url)
{
echo $url;
mysql_select_db($database_spyware, $spyware) || die(mysql_error());
$select_url= "select product_id from sp_url where url like '%{$url}%'";
echo $select_url;
$run_url= mysql_query($select_url, $spyware);
$result_descr = mysql_fetch_assoc($run_url);
echo $result_descr;
return $result_descr;
}
?>
mysql_select_db()
expects the second parameter to be a resource identifier = your connection. The problem is, that you are running this as a function, inside which your connection is not established. You have to start your function with something like this:
function Visit($url)
{
$spyware = mysql_connect(); // set this to connect properly
echo $url;
mysql_select_db($database_spyware, $spyware) || die(mysql_error());
// the rest of your function goes on ...
I would asume that these two vars $spyware
and $database_spyware
are null
because they are defined (if at all) outside of your function's scope and not declared as global. Try to add
global $database_spyware, $spyware
at the beginning of function Visit(..).
Did you check if your initial database connection call succeeded? That returns false on failure, as most of the mysql functions do. As well, you haven't checked if the query succeeded. Most likely it failed and returned FALSE, which you then passed into the fetch call:
$database_spyware = mysql_connect(...);
if ($database_spyware === FALSE) {
die("Connection failed: " . mysql_error());
}
... etc ...
$run_query = mysql_query(...);
if ($run_query === FALSE) {
die("Query failed: " . mysql_error());
}
should be the bare mininum acceptable error handling.
精彩评论