473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why do I keep getting this error message?

3 New Member
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
  2.  
  3.  
  4. $input = $_POST['Rating'];
  5.  
  6.  
  7. //connect to database
  8. $link = mysql_connect("localhost", "name", "pword"); 
  9. $db = mysql_select_db("test", $link);
  10.  
  11.  
  12. $query = "SELECT RatingID FROM rating WHERE rating.Rating ='$input'";
  13. $result = mysql_query($query, $db) or die(mysql_error()); 
  14.  
  15. $row = mysql_fetch_array($result);
  16.         echo "Rating ID - ". $row['RatingID'];
  17.  
  18.  
  19.  
  20. ?>
Feb 18 '10 #1
5 1620
Atli
5,058 Recognized Expert Expert
Hey.

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. }
  6.  
  7. // Or simply:
  8. $link = mysql_connect('host', 'usr', 'pwd') or die(mysql_error());
Feb 18 '10 #2
Horhay5150
3 New Member
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
Atli
5,058 Recognized Expert Expert
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
Atli
5,058 Recognized Expert Expert
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)
  3.  
  4. // Should be
  5. mysql_query($query, $link)
Feb 18 '10 #5
Horhay5150
3 New Member
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

8
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...
4
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...
2
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...
2
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...
13
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
3
by: Franko | last post by:
I get the following error. Ihave no idea why? Pl help Server Error in '/WebApplication1' Application. -------------------------------------------------------------------------------- Compilation...
8
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...
8
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...
8
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...
10
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.