473,811 Members | 4,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql_num_rows error...

luckysanj
69 New Member
Expand|Select|Wrap|Line Numbers
  1. $sql_result=mysql_query($query) or die("Error in Checking User".mysql_error()); 
  2.         echo $no=mysql_num_rows($sql_result);
  3.              if($no<>1)
  4.                 {
  5.                 return(false);
  6.                 }
  7.             else
  8.                 {
  9.                 return (true);
  10.                 }
  11.  
In this code i have get this type of error:
Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\my\test\query\function.php on line 2
  2.  
Can any one guide me. How is error occured?

Thank you
Jul 27 '09 #1
14 1994
bilibytes
128 New Member
You are not doing the query well.

you should pass a mysql connection to the query so that it knows where to query.

Expand|Select|Wrap|Line Numbers
  1. $link = mysql_connect('hostName', 'userName', 'passWord');
  2.  
  3. //then select the db
  4.  
  5. mysql_select_db('databaseName', $link);
  6.  
  7. //then you can make your queries passing the $link
  8.  
  9. $resultSet = mysql_query('SELECT * FROM Table1', $link);
  10.  
  11. //now you can check if there are results
  12. if(mysql_num_rows(0 < $resultSet)){
  13.     echo 'yeah coolm, i have a result'
  14. }
  15. else{
  16.      echo 'wtf nothing from db';
  17. }
  18.  
Jul 27 '09 #2
Markus
6,050 Recognized Expert Expert
Your mysql_query() doesn't return a valid resource - what is the query?

Also, you if/else block can be shortened like so:

Expand|Select|Wrap|Line Numbers
  1. return ($no !== 1);
  2.  
  3. // as opposed to this:
  4. if($no <> 1) {
  5.     return FALSE;
  6. }
  7. else {
  8.     return TRUE;
  9. }
  10.  
Jul 27 '09 #3
Markus
6,050 Recognized Expert Expert
Billibytes beat me to it.

Anyway, couple of things: You do not have to pass a link resource to the mysql_* functions - if you do not, mysql will use the last opened connection.

Also:
Expand|Select|Wrap|Line Numbers
  1. if(mysql_num_rows(0 < $resultSet)){
  2.     echo 'yeah coolm, i have a result'
  3. }
  4. else{
  5.      echo 'wtf nothing from db';
  6. }
  7.  
will not work, but I think that's just a typing error on your part ;)

Expand|Select|Wrap|Line Numbers
  1. if(mysql_num_rows($resultSet) < 0){
  2.     echo 'yeah coolm, i have a result'
  3. }
  4. else{
  5.      echo 'wtf nothing from db';
  6. }
  7.  
Jul 27 '09 #4
bilibytes
128 New Member
@Markus
right, i have answered too quickly...
Jul 27 '09 #5
luckysanj
69 New Member
ok yet i have not solved my problem. so i send my three php page content.
1. index.php
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="post" action="check.php?id=tbl1">
  2.   <table width="200" border="1">
  3.     <tr>
  4.       <td colspan="2">Pesonal Info Table 1 </td>
  5.     </tr>
  6.     <tr>
  7.       <td width="72">Name:</td>
  8.       <td width="112"><input name="name" type="text" id="name" value="Ashok" /></td>
  9.     </tr>
  10.     <tr>
  11.       <td>Address</td>
  12.       <td><input name="address" type="text" id="address" value="Kathmandu" /></td>
  13.     </tr>
  14.     <tr>
  15.       <td><input name="tbl1" type="submit" id="tbl1" value="Submit" /></td>
  16.       <td><input type="reset" name="Submit2" value="Reset" /></td>
  17.     </tr>
  18.   </table>
  19. </form>
  20.  
  21.  
2. check.php
Expand|Select|Wrap|Line Numbers
  1.     <?php
  2.     foreach($_POST as $key=>$value)
  3.         { 
  4.         //echo "</br>";
  5.         $key.":".$$key=$value;
  6.         //echo "</br>".$key;
  7.         }
  8.         include_once("function.php");
  9.         $tblname= $_GET['id'];
  10.         $db=new Functions;
  11.         $db->dbconnection();
  12.     if(isset($tbl1))
  13.         {
  14.         $field=array('name','address');    
  15.         $value=array($name,$address);
  16.         $y=$result=$db->InsertData($tblname,$field,$value);
  17.         /*if($y==true)
  18.             {
  19.                 echo "Success";
  20.             }
  21.             else
  22.             {
  23.             echo "Failed";
  24.             }*/
  25.         }
  26.     if(isset($tbl2))
  27.         {
  28.         $field=array('phone','email');    
  29.         $value=array($phone,$email);
  30.         $result=$db->InsertData($tblname,$field,$value);
  31.         }
  32. ?>
  33.  
3. function.php
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. class Database
  3. {
  4. function dbconnection() 
  5.     {
  6.     $link=mysql_connect("localhost","root","") or die("Failed Connecting to Database");
  7.     mysql_select_db("query",$link) or die("Failed Connecting To Database");    
  8.     }
  9. }    
  10. class Functions extends Database
  11. {
  12. function InsertData($TblName,$Fields,$Values)  
  13.         {  
  14.         $query="INSERT INTO `{$TblName}` (`".(is_array($Fields)?implode("`,`",$Fields):$Fields)."`) 
  15.                 VALUES (".(is_array($Values)?"'".implode("','",$Values)."'":$Values).")"; 
  16.         $sql_result=mysql_query($query) or die("Error in Checking User".mysql_error()); 
  17.         echo $no=mysql_num_rows($sql_result);
  18.              if($no<>1)
  19.                 {
  20.                 return(false);
  21.                 }
  22.             else
  23.                 {
  24.                 return (true);
  25.                 }
  26.         } 
  27. }    
  28. ?>
  29.  
  30.  
But Still Error is same
Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\my\test\query\function.php on line 17
  2.  
Jul 27 '09 #6
Canabeez
126 New Member
Try this as function.php
Expand|Select|Wrap|Line Numbers
  1. class Database
  2. {
  3.     private $link;
  4.     function dbconnection() 
  5.     {
  6.         $this->link=mysql_connect("localhost","root","") or die("Failed Connecting to Database");
  7.         mysql_select_db("query",$this->link) or die("Failed Connecting To Database");    
  8.     }
  9. }    
  10. class Functions extends Database
  11. {
  12.     function InsertData($TblName,$Fields,$Values)  
  13.     {  
  14.         $query="INSERT INTO `{$TblName}` (`".(is_array($Fields)?implode("`,`",$Fields):$Fields)."`) 
  15.         VALUES (".(is_array($Values)?"'".implode("','",$Values)."'":$Values).")"; 
  16.         $sql_result=mysql_query($query, $this->link) or die("Error in Checking User".mysql_error());
  17.  
  18.         /* This line is to debug your query */ echo "<!-- QUERY: {$query} -->";
  19.  
  20.         $no = mysql_num_rows($sql_result);
  21.         echo ($no != 1);
  22.     }
  23. }
  24.  
Jul 27 '09 #7
bilibytes
128 New Member
I suggest that you go step by step.

first check that you get the data from the brower, and try to echo it.

then try to connect to the db and make a query with data you write in your file, not from $_POST

and try to output it.

and so on, you have to narrow down the search until you know where the problem comes from.

once you know where your code fails, come back and we will guide you.
Jul 27 '09 #8
luckysanj
69 New Member
This error is occur Canabeez sir,

Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\my\test\query\function.php on line 18
  2. Error in Checking User
  3.  
Jul 27 '09 #9
Markus
6,050 Recognized Expert Expert
echo() the $query variable, and post the output here. Your SQL is wrong, most likely.
Jul 27 '09 #10

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

Similar topics

5
21540
by: Arjan | last post by:
I've got the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/wbdfdart/public_html/wbdfforum/verwijder.php on line 13 verwijder.php 1 2 3 4 5
4
2111
by: David Nikel | last post by:
I am attempting to create a login script. The following snippet of code: $query = "select * from auth where username='$username' and password=password('$password')"; $result = mysql_query($query, $db_conn); $num = mysql_num_rows($result); echo $num;
4
1754
by: Fish44 | last post by:
Ive got the following code which works great on my localserver, but when i upload it to my service provider i get an error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /opt2/home3/mitas/public_html/register.php on line 86 It seems to be only this function mysql_num_rows() causing a problem, and the rest of the code works ok, and it adds data correctly.
7
1919
by: Dejan | last post by:
Hi Sorry for my terreble english. On my local (win) comp i have apache+mysql+php 4.05 I'm counting rows using mysql_num_rows function, and everything works fine. When i upload php file on server it says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/optikara/public_html/crosun/izn/insert_form.php on line 80
2
18904
by: 00webman | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/scripts/07/view_users.php on line 15 Can anyone spot my error?!? Thanks. <?php # Script 7.6 - view_users.php (2nd version after Script 7.4) // This script retrieves all the records from the users table. $page_title = 'View the Current Users'; include ('./includes/header.html');
3
1589
The1corrupted
by: The1corrupted | last post by:
Okay, this has blown my entire perception of reality way out of order. First, a page was working and not five minutes later, I get this error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Vardaes\gendisp.php on line 66 and I made insignificant changes to the script before hand that had nothing to do with mysql_num_rows();... Here's line 66 $saynum=mysql_num_rows(mysql_query("SELECT `cn`...
1
1645
by: d3vkit | last post by:
Alright I can not figure this one out, so I'm guessing it's some simple typo and some extra eyes will help me spot it. Here's the query (already connected to DB everything works in that respect): $inactiveQuery = "SELECT userid,email_address,username,signup_date FROM users WHERE activated = 0"; $inactiveResult = mysql_query($inactiveQuery) or die('error: query failed: '.mysql_error()); $inactiveNumRows = mysql_num_rows($inactiveResult)...
3
13026
by: Sandman | last post by:
Hi, So I read the manual where it says to use mysql_affected_rows() for everything except SELECT and SHOW, and use mysql_num_rows() for those two, which actually return a result. However, I wrote this little script below where I find that mysql_num_rows() returns exactly the same output in the case of SELECT, as mysql_affected_rows(). In the case of the INSERT, mysql_num_rows() does not return anything.
4
3632
by: seigaku | last post by:
Hi everyone, I've recently begun learning PHP and it looks like I took on too much so soon. I'm attempting to fix a php script that detects whether or not a person is Eligible to join a tournament or not when they register and attempt to join. I'm doing it locally at the moment so i don't need to upload every 5 minutes. Any assistance would be appreciated. On register.php, I am receiving the following error: Warning:...
0
10644
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
10127
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
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...
1
7665
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
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
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.