473,408 Members | 2,832 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,408 software developers and data experts.

Supplied argument is not a valid MySQL result resource.

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_array(): 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 2223
Dormilich
8,658 Expert Mod 8TB
I guess the query failed and thus returned false (which is not a valid resource).
Feb 5 '09 #2
Thanks for you reply.But resource are correct..
Feb 5 '09 #3
Atli
5,058 Expert 4TB
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
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
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">...
4
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...
2
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...
1
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...
11
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...
5
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...
4
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...
2
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...
2
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: <?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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,...
0
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...

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.