473,503 Members | 939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADODB recordcount returns 0 although is should be 1

1 New Member
Hey everyone,

I have the problem that one and the same SQL query returns two different results.

1. When executed in PHPMyAdmin, the query returns 1 record set.

2. When executed in the script, recordcount returns 0.

This is the query in plain:

select users.uid, users.name, users.mail, users.status, users_roles.uid, users_roles.rid, role.rid from users LEFT JOIN users_roles ON (users.uid = users_roles.uid) LEFT JOIN role ON (users_roles.rid = role.rid) WHERE users.name = 'username' AND MD5('password') = users.pass AND role.rid = 3

And this is the relavant code segment:

Expand|Select|Wrap|Line Numbers
  1. if (!$adodb_drupal) $adodb_drupal = connect_adodb(DB_NAME_DRUPAL);
  2.  
  3.     //Check the input for illegal chars
  4.     $current_username     = check_input($_POST['username'],"username");
  5.     $current_password     = check_input($_POST['password'],"password");
  6.  
  7.     // check the input with concrete rules
  8.     $input_check     = "";
  9.     $input_check  .= check_username($current_username);
  10.     $input_check  .= check_password($current_password);
  11.  
  12.     // Input check is only filled if either the username or the password is worng! This is done in the function check_username/check_password.
  13.     // Username/password are wrong if they contain certain characters or are too long or empty! 
  14.     if ($input_check != "") 
  15.     {                    
  16.         // output/log
  17.         update_log(trim($input_check,"\,"));                                        
  18.     }
  19.  
  20.     // Check user in Drupal DB
  21.  
  22.     $current_password = utf8_encode($current_password);
  23.  
  24.     $query = "select 
  25.                 users.uid,
  26.                 users.name,
  27.                 users.mail,
  28.                 users.status,
  29.                 users_roles.uid,
  30.                 users_roles.rid,
  31.                 role.rid
  32.                 from users
  33.                 LEFT JOIN users_roles ON (users.uid = users_roles.uid)
  34.                 LEFT JOIN role ON (users_roles.rid = role.rid)
  35.                 WHERE users.name = '" . $current_username . "'  
  36.                 AND MD5('".$current_password."') = users.pass
  37.                 AND role.rid = 3";
  38.  
  39.     $result = $adodb_drupal->Execute($query);
  40.  
  41.     // IF the result is filled, the user exists and we check if the user is active or not
  42.     if (($result != FALSE) AND ($result->RecordCount() > 0))
  43.     {
  44.         // User found, checking status is active    
  45.         if ($result->fields['status'] == 1) 
  46.         {
  47.             update_log("SUCCESS - user/pwd match active user. Username: " . $current_username);
  48.             $_SESSION["uid"] = $result->fields['uid'];
  49.  
  50.             // If the user exists and is active we have "success"
  51.             $_SESSION["authorization"] = "success";
  52.             $_SESSION["action"] = "home";
  53.             $action = "home";
  54.             $validate ="1";
  55.             $_POST['validate'] = "1";
  56.  
  57.             $User_ID = $result->fields['uid'];
  58.         } 
  59.         else 
  60.         {
  61.             update_log("FAILED - user/pwd match user not active. Username: " . $current_username);
  62.  
  63.             // If the user exists, but is not active, we have "notactive"
  64.             $_SESSION['authorization'] = "notactive";
  65.         }                                        
  66.     } 
  67.     else 
  68.     {
  69.         update_log("FAILED - no user/pwd match. Username: " . $current_username);
  70.  
  71.         // If the user is not in the database we have "unknown"
  72.         $_SESSION['authorization'] = "unknown";        
  73.     }
  74.     $adodb_drupal->close();
  75.  
Does anyone have an idea? As I said, the query returns a result when executed in the database, but not in the script.

Cheers,

Fred
Jul 27 '11 #1
0 1197

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

Similar topics

1
2195
by: skeeterbug | last post by:
hi all, i'm new to using php, adodb and pgsql. i have a need to enter data into a database. however, i can't find a web example or tutorial that explains the nuts and bolts of how this is...
4
4961
by: Navin Kulshreshtha | last post by:
Hi folks, I'm opening a recordset with a SQL statement and then trying to use the .RecordCount property to count the number of rows in the recordset. For some reason, it is always returning -1....
7
41830
by: Serge Myrand | last post by:
Hi, I have an ADODB.RecordSet that RecordCount alway return -1 and this RecordSet is plenty of record! R.RecordSet = -1 R.eof = False R.BOF = False Is the cursor is lost somewhere?
0
1890
by: Dot Netizen | last post by:
I am having trouble passing an ADODB.Recordset from a VB6 application to a VB.Net class library using COM Interop. I am running this on XP SP2 with the .Net Framework 1.1 and MDAC 2.8 SP1. I've...
12
2947
by: scott | last post by:
In LISTING 2, I have a SPROC that returns a recordset and a recordcount in SQL QA. I can access the Recordset with no problem. How can I grab the Recordcount with ASP code at the same time I'm...
4
15117
by: jl | last post by:
Hello, I am trying to determine if a recordset is empty or not, and if it is empty print out a message saying no records found. I thought I could use rs.RecordCount but it always seems to return...
2
2064
by: nick_faye | last post by:
why does my recordcount returns the # of actual records + 1? btw, i am using ms access. i don't know what happened but at first, my table seems ok. the recordcount returns the correct # of...
2
3847
by: Rick Brown | last post by:
I get a "subscript out of range" error when I run this code. "Rcount = rsSupplierCode.RecordCount" Returns 49 BUT "numReturned = UBound(varRecords, 2) + 1" Returns only 3 I'm I wrong to...
1
3236
pureenhanoi
by: pureenhanoi | last post by:
I'm using VB6 and MSAcces DataBase my project have one Conection called: GPcnxn, a Recordset called: GPrs. If i connect to database by DataEnvironment, so, after this command Set...
8
19106
code green
by: code green | last post by:
I have been working with a script I have inherited that uses the ADODB class. I want to run a query that checks a record is unique across the primary key and date field in a MsSql DB before...
0
7089
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...
1
6995
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...
0
7463
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...
1
5017
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
3168
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...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
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 ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
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...

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.