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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment 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. ?> Quote Link to comment 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.. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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); ?> Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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: starsftw@hotmail.com It will be much easier that way. Quote Link to comment Share on other sites More sharing options...
msafvati Posted January 12, 2008 Author Share Posted January 12, 2008 i havent hotmail id i use msafvati@yahoo.com and masafvati@gmail.com Quote Link to comment Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 i havent hotmail id i use msafvati@yahoo.com and masafvati@gmail.com Yahoo users can add MSN users. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.