supplied argument is not a valid MySQL-Link resource error

Posted on 2011-05-11
Last Modified: 2012-05-11
I'm getting an error on line 11, saying Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource. What does this mean?

$con = mysql_connect("localhost","","");
	if (!$con)
 	 die('Could not connect: ' . mysql_error());

	mysql_select_db("", $con);

$query = mysql_query("SELECT description, cross_streets, title, town, feeornofee, lease, phone, contact, office, email, rent FROM apartments WHERE description LIKE '%$search%' ¦¦ cross_streets LIKE '%$search%' ¦¦ title LIKE '%$search%' ¦¦ town LIKE '%$search%' ¦¦ feeornofee LIKE '%$search%' ¦¦ lease LIKE '%$search%' ¦¦ phone LIKE '%$search%' ¦¦ contact LIKE '%$search%' ¦¦ contact LIKE '%$search%' ¦¦ office LIKE '%$search%' ¦¦ email LIKE '%$search%' ¦¦ rent LIKE '%$search%'", $db);

if ($query) 
echo "<table width=100% border=0 cellpadding=0 cellspacing=5 class=border_playlist_table><tr>";

while ($myrow = mysql_fetch_array($query)) { // Begin while 
$title = $myrow["title"]; 
$town = $myrow["town"];
$contact = $myrow["contact"]; 
$office = $myrow["office"]; 
$phone = $myrow["phone"]; 
$rent = $myrow["rent"]; 
echo "<tr class=sub_1><td colspan=4>$title : $town</td></tr> 
<tr bgcolor=#55556F><td><p><a href=$url target=_blank>$url</a></p></td> 
<tr bgcolor=#55556F><td colspan=4>$office</td></tr> 
<tr bgcolor=#55556F><td colspan=4>$phone</td></tr> 
<tr><td colspan=4>&nbsp;</td></tr>"; 
} // end while 
echo "</tr></table>"; 
echo "Search string is empty. <br> Go back and type a string to search"; 

Open in new window

Question by:genesisvh
    LVL 1

    Expert Comment

    Hey. Did you ever try to insert you database name on "mysql_select_db("  your Database name  ", $con);" . if it's not work I think some value of your select seem don't have any value. try to check value again in mysql command.


    Author Comment

    I have put in the name I just excluded it here.
    LVL 82

    Expert Comment

    by:Dave Baldwin
    You have '$db' on line 11 but you have '$con' on line 3.  They should match.  '$con' is the 'Resource ID' from the connection.
    LVL 1

    Expert Comment

    DaveBaldwin: Oh. It's true. Why I can't notice it. lol Oh It's a small mistake but make more trouble. LOL
    LVL 107

    Accepted Solution

    You don't need the $db variable at all in the query.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now