jbingman Posted September 2, 2007 Share Posted September 2, 2007 Hey im still having trouble with a login page http://www.fresnosar.com/php/login.php. when i enter the login in username and password, the database is connected but nothing happens. it tells me that the login failed. but everything seems to be in working order. heres my login and dbconnect script. login.php <? session_start(); ?> <? // dBase file include ("dbConfig.php"); if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `dbUser` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: member.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { echo "<form action=\"?op=login\" method=\"post\">"; echo "<table cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td width=\"146\" height=\"16\" colspan=\"2\"><div style=\"color:#FFFFFF; font-size:14px; white-space:2px; border-bottom:#000000 thin solid; border-top:#000000 thick solid\">FresnoSAR Login</div></td>"; echo "</tr><tr>"; echo "<td align=\"left\" style=\"border:#000000 thin solid\">"; echo "<div style=\"color:#FFFFFF; font-size:11px; white-space:2px\">Username:<br />"; echo "<input name=\"username\" id=\"username\" width=\"140\"/> </div> </td>"; echo "</tr><tr>"; echo "<td align=\"left\" style=\"border:#000000 thin solid\"><div style=\"color:#FFFFFF; font-size:11px; white-space:2px\">Password:<br />"; echo "<input type=\"password\" name=\"password\" width=\"140\" /></div></td>"; echo "</tr><tr>"; echo "<td height=\"25\" colspan=\"2\" align=\"center\" style=\"border:#000000 thin solid\"><input type=\"submit\" name=\"login\" value=\"Login\" />"; echo"</table></form>"; } ?> dbConfig.php <? $host = "localhost"; $user = "*myusername*"; $pass = "*mypassword*"; $db = "dbUser"; // This part sets up the connection to the // database (so you don't need to reopen the connection // again on the same page). $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } // Then you need to make sure the database you want // is selected. mysql_select_db($db); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/ Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 Firstly, do not use the mysql PASSWORD function for encryption. Is it not intended to be used by client code and is liekly to brake your application in the future. Read the manual for more details. Secondly, you never check your query succeeds before using it. At minimum you need.... $r = mysql_query($q) or die(mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339647 Share on other sites More sharing options...
jbingman Posted September 2, 2007 Author Share Posted September 2, 2007 ok. i basically just copied this from trap17. so im not really sure what all of the code means. and im pretty new to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339649 Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 Well, I wouldn't go copying any more code from there, this is pretty poorly written code. Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339650 Share on other sites More sharing options...
jbingman Posted September 2, 2007 Author Share Posted September 2, 2007 do you have any suggestions. any really good tutorials that could help? which one is more secure using a session or a cookie? Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339652 Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 Theres a good link in my signiture. Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339653 Share on other sites More sharing options...
jbingman Posted September 2, 2007 Author Share Posted September 2, 2007 very informational but im looking for more tutorialized kind of thing. teaches me what to do and what it means. Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339658 Share on other sites More sharing options...
Timma Posted September 2, 2007 Share Posted September 2, 2007 I know of a site with lots of PHP tutorials, yet the site also contains warez so I don't think I can post it. Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339659 Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 The book in my signiture will teach you php from the ground up. If its just login tutoirlas your after, you might try the phpfreaks.com site itself, otherwise you'll need to google for them. I haven't done a tutorial in years so can't really recommend any. Quote Link to comment https://forums.phpfreaks.com/topic/67612-solved-trouble-with-login/#findComment-339661 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.