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
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.

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.