473,217 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,217 software developers and data experts.

Why do I keep getting this error message?

I am admittedly a noob to PHP and mySQL, Have been running through some tutorials. Whenever I run the following script I get this error message: mysql_query() expects parameter 2 to be resource, boolean given.

Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. <?php
  4. $input = $_POST['Rating'];
  7. //connect to database
  8. $link = mysql_connect("localhost", "name", "pword"); 
  9. $db = mysql_select_db("test", $link);
  12. $query = "SELECT RatingID FROM rating WHERE rating.Rating ='$input'";
  13. $result = mysql_query($query, $db) or die(mysql_error()); 
  15. $row = mysql_fetch_array($result);
  16.         echo "Rating ID - ". $row['RatingID'];
  20. ?>
Feb 18 '10 #1
5 1613
5,058 Expert 4TB

That means that your mysql_connect call is failing. When it is successful, it returns a resource that you can pass into the mysql_query function. However, when it is unsuccessful, it returns FALSE which, when passed into the mysql_query function, generates this error.

You should verify that the mysql_connect call was successful before trying to pass the $link to the mysql_query function.

For example:
Expand|Select|Wrap|Line Numbers
  1. // You can do:
  2. $link = mysql_connect('host', 'usr', 'pwd');
  3. if($link === false) {
  4.     die("MySQL connection could not be established: " . mysql_error());
  5. }
  7. // Or simply:
  8. $link = mysql_connect('host', 'usr', 'pwd') or die(mysql_error());
Feb 18 '10 #2
added the suggested code, error message is still the same. For some reason mysql_Query isnt happy with $db, as far as i have been able to tell though my syntax on both connect and db selection is correct, i'm stumped.
Feb 18 '10 #3
5,058 Expert 4TB
added the suggested code, error message is still the same.
That can't be possible. If you added either of those and the connection fails, the code should be stopped before it reached the query call.

Can you show us how you modified the code?
Feb 18 '10 #4
5,058 Expert 4TB
Ahhh ok. I see now. Never mind my previous post.

You are using the wrong variable in your mysql_query call. You should be using the result of the mysql_connect call, not the mysql_select_db call.

Expand|Select|Wrap|Line Numbers
  1. // This
  2. mysql_query($query, $db)
  4. // Should be
  5. mysql_query($query, $link)
Feb 18 '10 #5
THANK YOU. That did the trick. Appreciate the help.
Feb 18 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Lisa | last post by:
I have a drop down that defaults to "select" after the page refreshes. How do I keep the selected value in the dropdown field... I've tried EVERYTHING and nothing works! :( <script...
by: Chefry | last post by:
I'm trying to set up an off the shelf script and keep getting an error. My host set up the mysql on my site and I changed the variables I had to in the settings.php file but I keep getting the...
by: iainw | last post by:
HI All, 1st post here, i wonder if you can help. We are about to upload CMS t a windows server and keep getting 2 errors below. We need to go LIVE an it's delaying us. An error occured when...
by: WAYNEL | last post by:
Hi I am trying to re-write some of the example code that Agilent gives for VB to VB.Net. In .Net I keep getting the error 'cannot change the number of dimensions of an array'. I have paste...
by: Larry | last post by:
Hi I have asp.net programs. I used a very simple data transfer method by using URLs ˇ°First.aspxˇ± contents a line to send data to the ˇ°second.aspxˇ± page, for
by: Franko | last post by:
I get the following error. Ihave no idea why? Pl help Server Error in '/WebApplication1' Application. -------------------------------------------------------------------------------- Compilation...
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
by: illuzion | last post by:
ok I keep getting this error: Parse error: syntax error, unexpected T_VARIABLE in /home/illuzion/public_html/BAMF/contactus.php on line 38 and this error is possibly on other lines could...
by: charmeda103 | last post by:
My program keeps getting me and error and i dont why here is the error message error C2061: syntax error: identifier 'infile' error C2660: 'ReadDate' : function does not take 6 arguments...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.