473,657 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Supplied argument is not a valid MySQL result resource.

3 New Member
Hi I am new to Php.I am trying to read My sql database data from table to php.

I am getting this warning

Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource

and my code is
Expand|Select|Wrap|Line Numbers
  1.       <?php
  2.  
  3.       $con = mysql_connect("localhost","sandman","sandcastle");
  4.  
  5.       if (!$con)
  6.  
  7.       {
  8.  
  9.       die('Could not connect: ' . mysql_error());
  10.  
  11.       }
  12.  
  13.       print "Connected to MySQL<br>";
  14.  
  15.  
  16.  
  17.       mysql_select_db("sandbox", $con);
  18.  
  19.  
  20.  
  21.       $result = mysql_query("SELECT parcel,location from accessor");
  22.  
  23.  
  24.  
  25.       echo "<table border='1'>
  26.  
  27.       <tr>
  28.  
  29.       <th>Parcel</th>
  30.  
  31.       <th>Location</th>
  32.  
  33.         </tr>";
  34. while($row = mysql_fetch_array($result))
  35.  
  36.       {
  37.  
  38.       echo "<tr>";
  39.  
  40.       echo "<td>" . $row['parcel'] . "</td>";
  41.  
  42.       echo "<td>" . $row['location'] . "</td>";
  43.  
  44.  
  45.  
  46.       echo "</tr>";
  47.  
  48.       }
  49.  
  50.  
  51.       echo "</table>";
  52.  
  53.  
  54.  
  55.       mysql_close($con);
  56.  
  57.       ?>
  58.  
plz let me know where I am doing wrong
Feb 5 '09 #1
4 2284
Dormilich
8,658 Recognized Expert Moderator Expert
I guess the query failed and thus returned false (which is not a valid resource).
Feb 5 '09 #2
kalyanip14
3 New Member
Thanks for you reply.But resource are correct..
Feb 5 '09 #3
Atli
5,058 Recognized Expert Expert
Hi.

@kalyanip14
Apparently, they are not.
PHP warnings do not lie, and this one is telling you that the resource is not valid.

You should always make sure of this yourself before you try to use the resource returned by a function.
The usual way to do that with MySQL queries is to do:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("your query here") or die(mysql_error());
This prints the error you SQL is generating and stops the code from executing any further, if the SQL query fails.
If the SQL query is successful, it moves on the the next line of code.

If you want to handle this more gracefully, you can simply check the $result of the query before it is used. If it is FALSE, your query failed.
Feb 5 '09 #4
kalyanip14
3 New Member
I sloved it thanks for your help
Feb 9 '09 #5

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

Similar topics

3
3909
by: petemaxi | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9 <div class="left"> <div class="menu"> <div class="boxhead" style="text-align:center;"> <strong>Menu</strong> </div> <br /> <?php require ('includes/db_conn.inc.php'); $query = "select * from menu order by item_order"; $result = mysql_query($query);
4
7827
by: Ryanlawrence1 | last post by:
Heya, I get these 2 errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20 You have not entered all the fields Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 34 Sorry You failed to enter the correct old password I was wondering if anyone could help me, I have...
2
16920
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jplane/certcent/phpweb/quiz/index.php on line 21 PHP CODE:
1
2702
by: lsmamadele | last post by:
I am getting the following error messages in my search: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 113 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 127 My code is below. Any help would be much appreciated. ...
11
3591
by: Breana | last post by:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/category.php on line 88 ------------------------------------------- It does this when there is no result "empty table" how can i do a quick fix to say No Results... row 88: if ($myrow = mysql_fetch_array($result)) { do { if ($rowcolor == 1) {
5
2351
by: Mubs | last post by:
Hi, I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out.. could any1 help.. error:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18 Wrong Username or Password code:
4
5023
by: fisherd | last post by:
When i run this code, i keep getting this message; Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\checklogin.php on line 26 i use this code to check login details. Here is the code for the pages that i used. main_login.php <html> <body>
2
2193
by: perhapscwk | last post by:
When I run my site from localhost, no error, but when I move it to webhosting, it show below error, why? Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/asi50080/public_html/onlineadv/category.php on line 143 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/asi50080/public_html/onlineadv/category.php on line 155
2
3227
by: macdalor | last post by:
Hi! I'm completely new to all dev and trying to put a website together using MySQLI and PHP; was running fine until I try to gather the DB content with the following script: <? $username="xxxxxx"; $password="xxxxxx"; $database="maxalien_davidloran"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts";
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
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.