wikedawsum Posted January 8, 2007 Share Posted January 8, 2007 Hello all. I'm having some serious problems and cannot figure out what is going on. I've created a simple login script so I can check connections to my database, etc.. (been having problems for a while and am doing this to narrow them down). My login form is as follows:[code]<form name="authenticate" method="post" action="login.php"><input name="username" type="text" value="username" size="20"/><br><input name="passwd" type="text" value="passwd" size="20"/><br><input type="submit" name="submit" value="submit"/><input type="reset" name="reset" value="reset"/></form>[/code]login.php:[code]<?php@mysql_connect("mysql.aacapartsandsupplies.com", "admin", "******") or die("Cannot connect to DB!");@mysql_select_db("tokens") or die("Cannot select DB!");$sql="SELECT username FROM user WHERE username='$username' and passwd=sha1('$passwd')";$r = mysql_query($sql);if(!$r) {$err=mysql_error();print $err;exit();}if(mysql_affected_rows()==0){print "no such login in the system. please try again.";exit();}else{print "successfully logged into system.";//proceed to perform website’s functionality – e.g. present information to the user}?>[/code]Unless I am missing something, all of this seems to look ok to me. However, when I try to login with my registered username and password, I get the "no such login in the system. please try again" error. What confuses me is that the username IS registered, and I can view that information by visiting [url=http://www.aacapartsandsupplies.com/users.php]http://www.aacapartsandsupplies.com/users.php[/url]. So, if the user is registered, why is it telling me they're NOT registered? If you want to check the form out it's located at [url=http://www.aacapartsandsupplies.com/login.html]http://www.aacapartsandsupplies.com/login.html[/url]. Again, these are just test pages and are not secure or anything. I'm just trying to narrow down my problems.Hopefully I've explained this well enough. Thanks to anyone who can give me some insight. Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/ Share on other sites More sharing options...
fert Posted January 8, 2007 Share Posted January 8, 2007 change [code]$r = mysql_query($sql);[/code]to[code]$r = mysql_query($sql) or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156185 Share on other sites More sharing options...
wikedawsum Posted January 8, 2007 Author Share Posted January 8, 2007 Thanks for your reply. That did get rid of "no such login...", but it only displays a blank page. It doesn't tell me that I've successfully logged in as it should. Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156203 Share on other sites More sharing options...
Asheeown Posted January 8, 2007 Share Posted January 8, 2007 [code]<?php@mysql_connect("mysql.aacapartsandsupplies.com", "admin", "******") or die("Cannot connect to DB!");@mysql_select_db("tokens") or die("Cannot select DB!");$sql="SELECT username FROM user WHERE username='$username' and passwd=sha1('$passwd')";$r = mysql_query($sql);if(!$r) {$err=mysql_error();print $err;exit();}if(mysql_affected_rows()==0){print "no such login in the system. please try again.";exit();}else{print "successfully logged into system.";//proceed to perform website’s functionality – e.g. present information to the user}?>[/code]should have to change if(mysql_affected_rows()==0){if im not mistakenbecause then mysql_affected_rows has no array to actually look for so it should beif(mysql_affected_rows($sql)==0){If you just have a white screen it might be an error that your not seeing take out the die part and see if it works Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156206 Share on other sites More sharing options...
wikedawsum Posted January 8, 2007 Author Share Posted January 8, 2007 Fearsolider, tried using your suggestion..[code]<?php@mysql_connect("mysql.aacapartsandsupplies.com", "admin", "bc5106") or die("Cannot connect to DB!");@mysql_select_db("tokens") or die("Cannot select DB!");$sql="SELECT username FROM user WHERE username='$username' and passwd=sha1('$passwd')";$r = mysql_query($sql);if(!$r) {$err=mysql_error();print $err;exit();}if(mysql_affected_rows($sql)==0){print "no such login in the system. please try again.";exit();}else{print "successfully logged into system.";//proceed to perform website’s functionality – e.g. present information to the user}?>[/code]Received this error:Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/.doris/aacatest/test.aacapartsandsupplies.com/members/login.php on line 12no such login in the system. please try again. Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156212 Share on other sites More sharing options...
High_-_Tek Posted January 8, 2007 Share Posted January 8, 2007 That implies that the query you used is not valid, although it should show up in an mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156214 Share on other sites More sharing options...
fert Posted January 8, 2007 Share Posted January 8, 2007 whoopsI posted my code wrongI meant to sayChange[code]$r = mysql_query($sql);[/code]to[code]$r = @mysql_query($sql) or die(mysql_error());[/code]andchange[code]if(mysql_affected_rows($sql)==0){[/code]to[code]if(mysql_affected_rows($r)==0){[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156216 Share on other sites More sharing options...
wikedawsum Posted January 9, 2007 Author Share Posted January 9, 2007 [quote]whoopsI posted my code wrongI meant to sayChangeCode:$r = mysql_query($sql);toCode:$r = @mysql_query($sql) or die(mysql_error());andchangeCode:if(mysql_affected_rows($sql)==0){toCode:if(mysql_affected_rows($r)==0){[/quote]That gave me the same error.[quote]That implies that the query you used is not valid, although it should show up in an mysql_error()[/quote] I'm not sure how my query could be wrong.. I have a database named tokens with a table named user. username and passwd are two of the fields in the table. Not sure what could be wrong with the query. Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156222 Share on other sites More sharing options...
fert Posted January 9, 2007 Share Posted January 9, 2007 try this:change[code]$sql="SELECT username FROM user WHERE username='$username' and passwd=sha1('$passwd')";[/code]to[code]$password=sha1($password);$sql="SELECT username FROM user WHERE username='$username' and passwd='$password'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156226 Share on other sites More sharing options...
wikedawsum Posted January 9, 2007 Author Share Posted January 9, 2007 No luck. Still saying I'm not registered. I tried creating a new database thinking perhaps I had setup something wrong in the original one. That didn't help. I have used databases with login scripts on this site before and they have worked fine. I'm about ready to pull my hair out! Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156656 Share on other sites More sharing options...
HuggieBear Posted January 9, 2007 Share Posted January 9, 2007 You're using the wrong function... [color=red]mysql_affected_rows()[/color] only works after INSERT, UPDATE, REPLACE or DELETE statements. For SELECT statements you want to use [color=blue]mysql_num_rows()[/color]Use this:[code]<?php// Connect to db@mysql_connect("mysql.aacapartsandsupplies.com", "admin", "******") or die("Cannot connect to DB!");// Select db@mysql_select_db("tokens") or die("Cannot select DB!");// Run query$sql = "SELECT username FROM user WHERE username='$username' and passwd=sha1('$passwd')";$r = mysql_query($sql);if(!$r){ $err=mysql_error(); echo $err; exit();}// Check if user existsif(mysql_num_rows() == 0){ echo "no such login in the system. please try again."; exit();}else{ echo "successfully logged into system."; // present information to the user}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156658 Share on other sites More sharing options...
wikedawsum Posted January 9, 2007 Author Share Posted January 9, 2007 Thank you, HuggieBear! That got it working.I did have to change[quote]if(mysql_num_rows() == 0){[/quote]to [quote]if(mysql_num_rows($r) > 0){[/quote]Thank you everyone for input and suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156676 Share on other sites More sharing options...
HuggieBear Posted January 9, 2007 Share Posted January 9, 2007 Oh yeah, sorry, I missed out your result resource. That's copying and pasting for you :)RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33402-solved-problems-with-login-script/#findComment-156677 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.