snallemap Posted September 22, 2010 Share Posted September 22, 2010 Hello Php Freaks I am following this tutorial how to make a login for my website, the only trouble is that... It dosen't seem to work, so i wanna know if its only me who cant make it work... and if it is why XD... Tutorial can be found here: http://www.knowledgesutra.com/forums/topic/7887-php-simple-login-tutorial/ Now when i get started it starts saying error at line 6: if ($_GET["op"] == "login") It says that when im about to login right above the login. Now when i put in data i get error on line 19: $r = mysql_query($q); That one, and i have no idea how to fix it. Anyone please ? Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/ Share on other sites More sharing options...
KevinM1 Posted September 22, 2010 Share Posted September 22, 2010 What do the error messages actually say? Also, post your existing code. Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1113947 Share on other sites More sharing options...
snallemap Posted September 22, 2010 Author Share Posted September 22, 2010 Here is the login.php <?php session_start(); // dBase file include "config.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `gusers` " ."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: members.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { //If all went right the Web form appears and users can log in echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"username\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; } ?> When i open the login.php it says: Notice: Undefined index: op in C:\wamp\www\kawaii\login.php on line 6 Above the actual login.. When i write in the code and tries to login i get: Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\kawaii\login.php on line 19 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\kawaii\login.php on line 19 Sorry, could not log you in. Wrong login information. Please help Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114077 Share on other sites More sharing options...
trq Posted September 22, 2010 Share Posted September 22, 2010 Your database credentials are incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114087 Share on other sites More sharing options...
snallemap Posted September 22, 2010 Author Share Posted September 22, 2010 <? $host = "localhost"; $user = "root"; $pass = "test123"; $db = "kawaii"; $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } mysql_select_db($db); ?> This is my config that i link to though login.php using include.... Is there any wrong things in it ?.. If so what is it :/ Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114127 Share on other sites More sharing options...
PFMaBiSmAd Posted September 22, 2010 Share Posted September 22, 2010 It's likely that the short open tag you are using is causing your connection code to not be seen as php code. What do you get when you do a 'view source' in your browser when you goto the login.php page? Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114134 Share on other sites More sharing options...
snallemap Posted September 22, 2010 Author Share Posted September 22, 2010 <? $host = "localhost"; $user = "root"; $pass = "test123"; $db = "kawaii"; $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } mysql_select_db($db); ?><br /> <b>Notice</b>: Undefined index: op in <b>C:\wamp\www\kawaii\login.php</b> on line <b>6</b><br /> <form action="?op=login" method="POST">Username: <input name="username" size="15"><br />Password: <input type="password" name="password" size="8"><br /><input type="submit" value="Login"></form> I took your word to me and made the config longer, now it works... but i still have the : Notice: Undefined index: op in C:\wamp\www\kawaii\login.php on line 6 on the loginpage which is really annoying... i dunno how to get that away. Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114139 Share on other sites More sharing options...
snallemap Posted September 22, 2010 Author Share Posted September 22, 2010 After testing it... It seems that login dosen't work anyways... if i enter the right login it still says that the login was wrong. This might be caused by the error on line 6? I got errors on my login page, but the login error was caused by too short password lenght (ruined the encrypted password) - Fixed already. I hope someone can help me with the login error on line 6 though Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114148 Share on other sites More sharing options...
herghost Posted September 22, 2010 Share Posted September 22, 2010 well you are still using <? instead of <?php so I would change all these to start with, then see if you still have the error Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114200 Share on other sites More sharing options...
merylvingien Posted September 22, 2010 Share Posted September 22, 2010 Having just glanced quickly at this post, whats the code of the form you are using to get the user details? Make sure you have named the input boxes correctly! Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114229 Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 Everything works except the Notice that appears above the login, i don't know what causes it since it seems like it shouldn't be a problem, in fact if i was removed the script wouldn't work... So strange Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114325 Share on other sites More sharing options...
sasa Posted September 23, 2010 Share Posted September 23, 2010 change if ($_GET["op"] == "login") to if (isset($_GET["op"]) and $_GET["op"] == "login") Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114373 Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 change if ($_GET["op"] == "login") to if (isset($_GET["op"]) and $_GET["op"] == "login") Tried it, and it worked! Thank you SO much Quote Link to comment https://forums.phpfreaks.com/topic/214069-tutorial-fail/#findComment-1114463 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.