Jump to content

Recommended Posts

It means that your mysql_connect() failed (or was never executed) and the link you put into the mysql_query() statement was not a valid MySQL-Link resource.

 

You would need to determine why your connection code failed and why your error checking logic in your code did not prevent the rest of your code from blindly attempted to execute a query when there was no connection.

Here is my code where I'm getting that error, perhaps maybe you might be able to see what I'm not. When I run this on my server here at home, it works perfect but when uploaded live...it give's me the error. I've talked to my Web host but they said it's in my scripting. So I would appreciate if someone could have a look. :)

 

"Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource "

 

//connect to database
$mysqli = mysqli_connect("", "", "", "");



  //Set the selected category
$selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false;

//show categories first
$get_cats_sql = "SELECT cat_id, cat_title FROM category ORDER BY cat_id";
$get_cats_res =  mysqli_query($mysqli, $get_cats_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($get_cats_res) < 1)
{
   $categoryList = "<p><em>Sorry, no categories to browse.</em></p>";
}
else
{
    //Display the categories
    while ($cats = mysqli_fetch_array($get_cats_res))
    {
        $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n";
        if ($cats['cat_id']==$selected_cat);
		}
		//get items
            $get_items_sql = "SELECT id, title, city, state, country, deadline, brief_description, activationkey, date FROM table WHERE  MONTH(date) = MONTH(CURDATE()) ORDER BY date";
            $get_items_res = mysqli_query($mysqli, $get_items_sql) or die(mysqli_error($mysqli));
            if (mysqli_num_rows($get_items_res) < 1)
            {
                $content = "<p><em>Sorry, no items in this category.</em></p>\n";
            }
            else
            {
                $content .= "<ul>\n";
                while ($items = mysqli_fetch_array($get_items_res))
                {
                    $item_url = "detail.php?id={$items['id']}";
                    $item_title = stripslashes($items['title']);
                    $item_city = $items['city'];
				$item_state = $items['state'];
				$item_country = $items['country'];
                    $item_deadline = $items['deadline'];
                $item_brief_description = $items['brief_description'];
                    $item_id = $items['id'];
                    $content .= "";


				$content .="<table width=\"693\" border=\"0\"><tr><td width=\"200\"><a href=$item_url>$item_title</a></td><tr><td class=blackfont width=\"251\">{$item_city}, {$item_state} - {$item_country}</td></tr><tr><td  class=blackfont width=\"109\">Deadline:  {$item_deadline}</td></tr><tr><td class=\"blackfont\">{$item_brief_description}</td></tr><br /></table>";

 $content .= "\n";
			}
			$content .= "</ul>\n";
			}

I took out the db connection details off the posting. 

 

In fact, I just ran another test on a different page that worked.  It was a form with no initial database call for dynamic information that called on a php page to add a record.  It worked perfect.  Hmmmmm...this has me stumped.

The error message you are posting is for a mysql_query() statement. The code you are posting is using mysqli statements, unless you have a library of user written functions to use mysqli statements on a system that does not have mysqli installed.

 

You would need to post the actual code that is producing that error.

I think you're going to want to upload a script to see if the mysqli extension is installed. Paste the following into a new file, save it as phpinfo.php and upload it. Then browse to www.yourdomain.com/phpinfo.php and see if the (long) list shows that mysqli is installed. You should see a section for it about halfway down the page. Once you've verified that it does or doesn't exist, delete the script from the server.

 

<?php
phpinfo();
?>

My server doesn't support the mysqli script.  I realized that when I uploaded it earlier and it gave me an error for that...not recognizing it. So I changed all the mysqli's to mysql's and the error that I posted before was the result.  Sorry for the miscommunication of my posting on that.  Here is the code without the "mysqli" included that is still giving me the error. :)  I've purposely left out the db connection info. Thanks for your help. :)

 

This is the line of code I get the error:

$get_cats_res =  mysql_query($mysql, $get_cats_sql) or die(mysql_error($mysql));

 

 

Here is the rest of the code:

 

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

session_start();



//connect to database
$mysql = mysql_connect("", "", "", "");



  //Set the selected category
$selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false;

//show categories first
$get_cats_sql = "SELECT cat_id, cat_title FROM category ORDER BY cat_id";
$get_cats_res =  mysql_query($mysql, $get_cats_sql) or die(mysql_error($mysql));

if (mysql_num_rows($get_cats_res) < 1)
{
   $categoryList = "<p><em>Sorry, no categories to browse.</em></p>";
}
else
{
    //Display the categories
    while ($cats = mysql_fetch_array($get_cats_res))
    {
        $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n";
        if ($cats['cat_id']==$selected_cat);
		}
		//get items
            $get_items_sql = "SELECT id, title, city, state, country, deadline, brief_description, date FROM table WHERE  AND MONTH(date) = MONTH(CURDATE()) ORDER BY date";
            $get_items_res = mysql_query($mysql, $get_items_sql) or die(mysql_error($mysql));
            if (mysql_num_rows($get_items_res) < 1)
            {
                $content = "<p><em>Sorry, no items in this category.</em></p>\n";
            }
            else
            {
                $content .= "<ul>\n";
                while ($items = mysql_fetch_array($get_items_res))
                {
                    $item_url = "detail.php?id={$items['id']}";
                    $item_title = stripslashes($items['title']);
                    $item_city = $items['city'];
				$item_state = $items['state'];
				$item_country = $items['country'];
                    $item_deadline = $items['deadline'];
                $item_brief_description = $items['brief_description'];
                    $item_id = $items['id'];
                    $content .= "";


				$content .="<table width=\"693\" border=\"0\"><tr><td width=\"200\"><a href=$item_url>$item_title</a></td><tr><td class=blackfont width=\"251\">{$item_city}, {$item_state} - {$item_country}</td></tr><tr><td  class=blackfont width=\"109\">Deadline:  {$item_deadline}</td></tr><tr><td class=\"blackfont\">{$item_brief_description}</td></tr><br /></table>";

 $content .= "\n";
			}
			$content .= "</ul>\n";
			}


}

?>

 

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.