Jump to content

odbc_num_rows Error


msafvati

Recommended Posts

hi

i have an error for this Code

 

Error :

Warning: odbc_num_rows(): 2 is not a valid ODBC result resource in C:\Documents and Settings\LapTop 1\Desktop\NONAME5.php on line 10

 

Code :

 

$connectionstring=odbc_connect("user","","");

$query= " select * from tblReguser where username = '".$_GET['txt1']."'";

$result=odbc_do($connectionstring,$query);

$user = odbc_result($result,"username");

odbc_close($connectionstring);

$Found = odbc_num_rows($result);

if($Found == 1){

echo"Username found in the database"; }

 

Please Guid me

thank u

 

Link to comment
Share on other sites

hi

i have an error for this Code

 

Error :

Warning: odbc_num_rows(): 2 is not a valid ODBC result resource in C:\Documents and Settings\LapTop 1\Desktop\NONAME5.php on line 10

 

Code :

 

$connectionstring=odbc_connect("user","","");

$query= " select * from tblReguser where username = '".$_GET['txt1']."'";

$result=odbc_do($connectionstring,$query);

$user = odbc_result($result,"username");

odbc_close($connectionstring);

$Found = odbc_num_rows($result);

if($Found == 1){

echo"Username found in the database"; }

 

Please Guid me

thank u

 

Yes, I've been recently having this problem too. Simple change in how its done fixes it.

$conn = odbc_connect("user","","");
$query = "SELECT COUNT(username) from tblReguser where username = '{$_GET['txt1']}'";
$result = odbc_exec($conn, $query);
$Found = odbc_result($result, 1); 
if ($Found == 1)
  {
    echo "Username found in the database";
    $query = "SELECT username from tblReguser where username = '{$_GET['txt1']}'";
    $result = odbc_exec($conn, $query);
    $username = odbc_result($result, 1);
  }

 

That should work. Give it a go and see how it works. There's bound to be another way (odbc_num_rows ALWAYS bugs on me..) but that should work.

Link to comment
Share on other sites

tnk for your guid

my problem is solved(with moving odbc_close) but it dont show me any output!

Please see Blow:

HTML Code :

<html>

<head>

<title>New document</title>

</head>

<body>

<form action="http://127.0.0.1:8080/NONAME5.php" method="GET">

<input type="text" name="txt1" />

<input type="text" name="txt2" />

<input type="submit" value="Submit" />

 

</form>

</body>

</html>

 

and php script :

$connectionstring=odbc_connect("user","","");
if (!$connectionstring) 
  {
  exit("Connection Failed: " . $connectionstring);
  }
   

$query=  " select * from tblReguser where username = '".$_GET['txt1']."'";
$result=odbc_do($connectionstring,$query);
if (!$result) 
  {
  exit("Error in SQL");
  } 
  $Found = odbc_num_rows($result); 
if($Found == 0){ 
  echo"Username found in the database"; 
    odbc_close($connectionstring);
   }

plz help me

Link to comment
Share on other sites

tnk for your guid

my problem is solved(with moving odbc_close) but it dont show me any output!

Please see Blow:

HTML Code :

<html>

<head>

<title>New document</title>

</head>

<body>

<form action="http://127.0.0.1:8080/NONAME5.php" method="GET">

<input type="text" name="txt1" />

<input type="text" name="txt2" />

<input type="submit" value="Submit" />

 

</form>

</body>

</html>

 

and php script :

$connectionstring=odbc_connect("user","","");
if (!$connectionstring) 
  {
  exit("Connection Failed: " . $connectionstring);
  }
   

$query=  " select * from tblReguser where username = '".$_GET['txt1']."'";
$result=odbc_do($connectionstring,$query);
if (!$result) 
  {
  exit("Error in SQL");
  } 
  $Found = odbc_num_rows($result); 
if($Found == 0){ 
  echo"Username found in the database"; 
    odbc_close($connectionstring);
   }

please help me

If $Found == 0 it means its not found. So that's pointless.

 

Try the script I posted.

Link to comment
Share on other sites

tnk you but i have problem with that yet!!!

$connectionstring=odbc_connect("user","","");
if (!$connectionstring) 
  {
  exit("Connection Failed: " . $connectionstring);
  }
   

$query=  " select * from tblReguser where username = '".$_GET['txt1']."'"; #and password = '".$_GET['txt2']."'";
$result=odbc_do($connectionstring,$query);
if (!$result) 
  {
  exit("Error in SQL");
  } 
$Found = odbc_num_rows($result); 
if($Found >= 1){ 
  echo"Username found in the database"; 
   }
    else{ 

    echo"No user with this Username found in the database";  
}  

     odbc_close($connectionstring);

Link to comment
Share on other sites

tnk you but i have problem with that yet!!!

$connectionstring=odbc_connect("user","","");
if (!$connectionstring) 
  {
  exit("Connection Failed: " . $connectionstring);
  }
   

$query=  " select * from tblReguser where username = '".$_GET['txt1']."'"; #and password = '".$_GET['txt2']."'";
$result=odbc_do($connectionstring,$query);
if (!$result) 
  {
  exit("Error in SQL");
  } 
$Found = odbc_num_rows($result); 
if($Found >= 1){ 
  echo"Username found in the database"; 
   }
    else{ 

    echo"No user with this Username found in the database";  
}  

     odbc_close($connectionstring);

<?
$conn = odbc_connect("user", "", "") or exit("Connection Failed: " . odbc_error($connectionstring));
$query = "SELECT * FROM tblReguser WHERE username = '{$_GET['txt1']}'"; #and password = '".$_GET['txt2']."'";
$result = odbc_exec($conn, $query) or exit("Error in SQL");
$Found = odbc_num_rows($result); 
if ($Found >= 1)
  		echo "Username found in the database"; 
else
    	        echo "No user with this Username found in the database";  

odbc_close($conn); # Only closed by choice, no need. PHP closes it automatically.
?>

 

If that fails to work, you're left with (as I've said above):

<?
$conn = odbc_connect("user", "", "") or exit("Connection Failed: " . odbc_error($connectionstring));
$query = "SELECT COUNT(*) FROM tblReguser WHERE username = '{$_GET['txt1']}'"; #and password = '".$_GET['txt2']."'";
$result = odbc_exec($conn, $query) or exit("Error in SQL");
$Found = odbc_result($result, 1); 
if ($Found >= 1)
                echo "Username found in the database"; 
else
    	        echo "No user with this Username found in the database";  

odbc_close($conn); # Only closed by choice, no need. PHP closes it automatically.
?>

Link to comment
Share on other sites

Thank u

but this Script that you guid me dont work!means dont show output for me.

my username is MSAFVATI when i write msafvati in text and send it with SUBMIT to php script,output of script is :

"No user with this Username found in the database "

while msafvati inserted in database in fieldname USERNAME..

 

Link to comment
Share on other sites

Thank u

but this Script that you guid me dont work!means dont show output for me.

my username is MSAFVATI when i write msafvati in text and send it with SUBMIT to php script,output of script is :

"No user with this Username found in the database "

while msafvati inserted in database in fieldname USERNAME..

 

 

You didn't have any output in the original script so I didn't include it in that.

 

<?
$conn = odbc_connect("user", "", "") or exit("Connection Failed: " . odbc_error($connectionstring));
$query = "SELECT COUNT(*) FROM tblReguser WHERE username = '{$_GET['txt1']}'"; #and password = '".$_GET['txt2']."'";
$result = odbc_exec($conn, $query) or exit("Error in SQL");
$Found = odbc_result($result, 1); 
if ($Found >= 1)
          {
                echo "Username found in the database"; 
                $result = odbc_exec($conn, "SELECT UserName FROM tblReguser WHERE username='{$_GET['txt1']}'");
                while ($row = odbc_fetch_array($result))
                   {
                      echo "{$row['username']}<br />"; # Basic output
                   }
          }
else
    	        echo "No user with this Username found in the database";  

odbc_close($conn); # Only closed by choice, no need. PHP closes it automatically.
?>

By the way, you should change the form type to a POST form and then use POST variables. But not necessary in this short script.

 

Link to comment
Share on other sites

i really ashemed of my work because i get your time!!

 

i want to change my script means :

can i compare my inputs (username Ans password) with values that insert in database?

please see example :

 

.
.

$user = odbc_result($result,"username");
$pass = odbc_result($result,"Password");
      if(($user==$_GET['txt1']) and ($pass == $_GET['txt2'])){ 
       echo "Username found in the database"; 
      } 
    else{ 
echo "No user found or more than one user found with the same names"; 
.
.

do this script is correct?

Link to comment
Share on other sites

i really ashemed of my work because i get your time!!

 

i want to change my script means :

can i compare my inputs (username Ans password) with values that insert in database?

please see example :

 

.
.

$user = odbc_result($result,"username");
$pass = odbc_result($result,"Password");
      if(($user==$_GET['txt1']) and ($pass == $_GET['txt2'])){ 
       echo "Username found in the database"; 
      } 
    else{ 
echo "No user found or more than one user found with the same names"; 
.
.

do this script is correct?

That wouldn't work as far as I know, without defining result retrievals as an array/associate array.

 

If it does happen to work (I'll run a couple of tests, but as far as I know it doesn't like that), that would be correct.. kind've.

However, your echoes are mis-informative.

 

Where it says, "Username found" it should be "Username found and matching attempted user and password".

Your method is wayyyy insecure, however, you're generally getting it.

 

I recommend posting the entire script (or is that the entire script?), and we'll see what we can do.

 

As for my time, I'm currently looking for some paying jobs to do for people. Like helping people, so here I am I wait. :)

Link to comment
Share on other sites

the complete Script is :

<?php 

$connectionstring=odbc_connect("user","","");
if (!$connectionstring) 
  {
  exit("Connection Failed: " . $connectionstring);
  }
   

$query=  " select * from tblReguser where username = '".$_GET['txt1']."'"; #and password = '".$_GET['txt2']."'";
$result=odbc_do($connectionstring,$query);
if (!$result) 
  {
  exit("Error in SQL");
  } 
   
   $user = odbc_result($result,"username");
   $Pass = odbc_result($result,"password");
    if(($user==$_GET['txt1']) and ($pass == $_GET['txt2'])){ 
    { 
     echo"Username found in the database";
       }
        else{ 
echo "No user found or more than one user found with the same names"; 
}  
     odbc_close($connectionstring);
?> 

Link to comment
Share on other sites

the complete Script is :

<?php 

$connectionstring=odbc_connect("user","","");
if (!$connectionstring) 
  {
  exit("Connection Failed: " . $connectionstring);
  }
   

$query=  " select * from tblReguser where username = '".$_GET['txt1']."'"; #and password = '".$_GET['txt2']."'";
$result=odbc_do($connectionstring,$query);
if (!$result) 
  {
  exit("Error in SQL");
  } 
   
   $user = odbc_result($result,"username");
   $Pass = odbc_result($result,"password");
    if(($user==$_GET['txt1']) and ($pass == $_GET['txt2'])){ 
    { 
     echo"Username found in the database";
       }
        else{ 
echo "No user found or more than one user found with the same names"; 
}  
     odbc_close($connectionstring);
?> 

 

I can't help you if you don't at least attempt my scripts. I'm at least 99% certain that my scripts work. I use ODBC nearly every day.

 

I see many flaws in there that I have pointed out and fixed in my scripts.

I am sorry, but I really can't help you any further.

Link to comment
Share on other sites

thank u

u guid me very well but i dont know where is problam..i attempt for your script but dont access result..this script is for my project i want to use this script for login user (very simple even without Session)

in my project remained only this section to it complete..for this script i missed 2 month from my time but...

 

Link to comment
Share on other sites

thank u

u guid me very well but i dont know where is problam..i attempt for your script but dont access result..this script is for my project i want to use this script for login user (very simple even without Session)

in my project remained only this section to it complete..for this script i missed 2 month from my time but...

 

Got MSN? Add me: starsftw@hotmail.com

 

It will be much easier that way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.