ryanfilard Posted October 21, 2011 Share Posted October 21, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/249500-mysql-link-not-valid/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2011 Share Posted October 21, 2011 $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. Quote Link to comment https://forums.phpfreaks.com/topic/249500-mysql-link-not-valid/#findComment-1281011 Share on other sites More sharing options...
ryanfilard Posted October 21, 2011 Author Share Posted October 21, 2011 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/249500-mysql-link-not-valid/#findComment-1281017 Share on other sites More sharing options...
ryanfilard Posted October 21, 2011 Author Share Posted October 21, 2011 I found it $news was in the required file. But I still get this Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/rweekly/public_html/2012/view_arguments.php on line 37 Quote Link to comment https://forums.phpfreaks.com/topic/249500-mysql-link-not-valid/#findComment-1281018 Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2011 Share Posted October 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249500-mysql-link-not-valid/#findComment-1281023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.