msafvati Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/ Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437152 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437166 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437169 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437171 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437173 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437176 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437177 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437180 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437183 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437188 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437190 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 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 https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437196 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 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: [email protected] It will be much easier that way. Link to comment https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437202 Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 i havent hotmail id i use [email protected] and [email protected] Link to comment https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437209 Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 i havent hotmail id i use [email protected] and [email protected] Yahoo users can add MSN users. Link to comment https://forums.phpfreaks.com/topic/85663-odbc_num_rows-error/#findComment-437212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.