Jump to content

MySQL-Link not valid


ryanfilard

Recommended Posts

What is wrong?

 

Warning: mysql_select_db(): supplied resource is not a valid MySQL-Link resource in /home/rweekly/public_html/2012/view_arguments.php on line 41

 

Warning: mysql_query(): supplied resource is not a valid MySQL-Link resource in /home/rweekly/public_html/2012/view_arguments.php on line 43

 

mysql_select_db($database_news, $news);
$query_news = "SELECT * FROM news WHERE id = '$id'";
$news = mysql_query($query_news, $news) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

mysql_select_db($database_news, $news);
$query_arguments = "SELECT * FROM argue WHERE pid = '$id'";
$arguments = mysql_query($query_arguments, $news) or die(mysql_error());
$row_arguments = mysql_fetch_assoc($arguments);
$totalRows_arguments = mysql_num_rows($arguments);

Link to comment
https://forums.phpfreaks.com/topic/249500-mysql-link-not-valid/
Share on other sites

$news is not a valid MySQL-Link resource and you would need to troubleshoot why it is not. It's either not getting set at all or it is not getting set to the result of a mysql_connect() statement.

 

I would recommend using a better name for a database connection variable than $news. It's fairly likely that you are using $news for some other purpose in your script and the connection resource got overwritten.

this is all of my php code

 

<?php require_once('Connections/news.php'); ?>
<?php
$id = $_REQUEST['id'];
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_news, $news);
$query_news = "SELECT * FROM news WHERE id = '$id'";
$news = mysql_query($query_news, $news) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

mysql_select_db($database_news, $news);
$query_arguments = "SELECT * FROM argue WHERE pid = '$id'";
$arguments = mysql_query($query_arguments, $news) or die(mysql_error());
$row_arguments = mysql_fetch_assoc($arguments);
$totalRows_arguments = mysql_num_rows($arguments);
?>

Someone already guessed what is causing the problem -

I would recommend using a better name for a database connection variable than $news. It's fairly likely that you are using $news for some other purpose in your script and the connection resource got overwritten.

 

You are using $news to hold the result from a mysql_query() statement. It is no longer the connection resource after that point in your code.

 

The names you use for variables should indicate the purpose of that variable. As already stated, $news is not a good name for a mysql connection.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.