Ungerbla Posted December 29, 2009 Share Posted December 29, 2009 Hi. can someone help me with my login? it wont work.. The error message is this: "Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\Main Login Page2.php on line 17 the server made a boo boo" <html> <head> <titel>Main Login Page</titel> <style type="text/css"> </style> </head> <body> <div id="loginform"> <form method ="post" action= <?php $host = "localhost"; $username = ""; $passowrd = ""; $db_name = "test"; $tbl_name = "members"; mysql_connect ($host, $username, $password) or die ("the server made a boo boo"); mysql_select_db (db_name) or die (mysql_error () ); $myusername = $_POST ['myusername']; $mypassowrd = $_POST ['mypassword']; $sql = "SELECT * FROM $members WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows ($result); if($count ==1) { session_register ("myusername"); session_register ("mypassowrd"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> <label for="username">Username:</label> <input type"text" name="myusername" id="username" /> <label for="password">Password:</label> <input type="password" name="mypassword" id="password" /> <input type="submit" name="submit" value="Login" /> </form> </div> </body> </html> i attatched a picture of my database [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/ Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 The error says it all.. Your username and/or password is incorrect for connection to mysql.. check that they are correct. or create a new user with access to the database you are trying to connect to.. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985357 Share on other sites More sharing options...
zobadof Posted December 29, 2009 Share Posted December 29, 2009 i dont know how to help but was wondering if you could help me? <p align="center"><a style="text-decoration: none" href="support.html">Customer Service</a> | <a style="text-decoration: none" href="Top%2040.html">Top 40</font></a> | <a style="text-decoration: none" href="home.html">Home</a> | <a style="text-decoration: none" href="videos.php">Videos</a> | <a style="text-decoration: none" href="logout.php">Logout</a> <div align="center"><img src="images/whitenoise.jpg"></div> <title>White Noise | Members</title> <div align="center"><h3>The members area will be updated at a later date, <p>Thank you for your patience,</p> <p>White Noise</p></div> i want it so if your not logged on you cant view the members page where as now you can just view members page without being logged in. can you help ? Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985358 Share on other sites More sharing options...
oni-kun Posted December 29, 2009 Share Posted December 29, 2009 You can check sessions, such as so if ($_SESSION['myusername'] == false) { header('Location: Login.php'); //Redirect them if they're not logged in. } Also, What is your PHP version? session_register() is depricated and will NOT work as expected in PHP >=5.3, you must assign as $_SESSION['key'] = 'value' Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985360 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 You can check sessions, such as so if ($_SESSION['myusername'] == false) { header('Location: Login.php'); //Redirect them if they're not logged in. } Also, What is your PHP version? session_register() is depricated and will NOT work as expected in PHP >=5.3, you must assign as $_SESSION['key'] = 'value' im using the latest WAMP server and i got PHP 5.3.0 and mysql 5.1.36 Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985364 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 zobadof: if you need help create your own topic and people will be able to help you instead of stealing this one Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985365 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 The error says it all.. Your username and/or password is incorrect for connection to mysql.. check that they are correct. or create a new user with access to the database you are trying to connect to.. as you might figured, i have no idea of what im doing.. i found this nice tutorial and though "its just copy and paste! " but it wassent.. witch i supose is good becouse im lerning! but culd you tell me what i need to do, i made a user that is allowed everywere. but it still dosent work.. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985366 Share on other sites More sharing options...
ignace Posted December 29, 2009 Share Posted December 29, 2009 @Buddski He already has but some people think they can do anything really. Their to dumb to make the required effort and they want help and they want it now even if they have to steal someone else's thread. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985370 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 ignace: too true.. as for this topic.. mysql_select_db (db_name) or die (mysql_error () ); needs to be mysql_select_db ($db_name) or die (mysql_error () ); And as for the main error.. When you created the mysql database did you create a username or password? Just gonna throw this out there.. set your $username to 'root' $host = "localhost"; $username = "root"; $password = ""; $db_name = "test"; $tbl_name = "members"; mysql_connect ($host, $username, $password) or die ("the server made a boo boo"); mysql_select_db ($db_name) or die (mysql_error () ); Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985375 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 @Buddski i think it works...cus i got some new errors... Main Login Page Notice: Undefined variable: password in C:\wamp\www\Main Login Page2.php on line 17 Notice: Undefined index: myusername in C:\wamp\www\Main Login Page2.php on line 20 Notice: Undefined index: mypassword in C:\wamp\www\Main Login Page2.php on line 21 Notice: Undefined variable: members in C:\wamp\www\Main Login Page2.php on line 23 Notice: Undefined variable: mypassword in C:\wamp\www\Main Login Page2.php on line 23 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Main Login Page2.php on line 26 Wrong Username or Password Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985379 Share on other sites More sharing options...
ChemicalBliss Posted December 29, 2009 Share Posted December 29, 2009 As buddski has mentioned, try the default mysql user/pass: root with no password. I believe WAMP would of asked you for a password for the root user. If not, then download the MySQL GUI Tools, google "MySQL Windows Password Reset" if you cannot get into mysql GUI Tools. Also, make sure you spell everything correctly, it will help later if you dont know how to spell things you wont know what variables are what. Anything you dont know just get a dictionaryt out or use one online. -CB- Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985380 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Ok lets work through these errors They all basically say 'You cant use that.. It doesnt exist...' Err #1: $password variable definition is spelt incorrectly you have $passowrd Err #2: Lines 20 and 21 are POST values which dont exist.. check to see what the form is posting. Err #3: You dont even have a members variable defined change where is has $members to $tbl_name Err #4: You spelt $mypassword incorreclty again.. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985385 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 Ok lets work through these errors They all basically say 'You cant use that.. It doesnt exist...' Err #1: $password variable definition is spelt incorrectly you have $passowrd Err #2: Lines 20 and 21 are POST values which dont exist.. check to see what the form is posting. Err #3: You dont even have a members variable defined change where is has $members to $tbl_name Err #4: You spelt $mypassword incorreclty again.. ok iv fixed all but those post things.. what whuld i do with those? :S Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985387 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Can you show us your form that submits to this script? Alternatively you can do this to see what is being posted echo '<pre>'; print_r($_POST); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985390 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 @Buddski emn.. Form.. hmm.. il just show you the entire thing cus i dont know what your looking for... This is: login_success <? session_start(); if(!session_is_registered(myusername)) { header("location:mainlogin.php); } ?> <html> <head><title>Welcome</title> </head> <body> <h1> Login was Successful<h1> <p> <a href="logout.php">Log Out!</a></p> </body> </html> This is logg out <? session_start(); session_destroy(); ?> <html> <head><title>Thanks</title> </head> <body> <h1>You've Logged Out</h1> </body> </html> and this is the main page ( the one iv showed allready..) <html> <head> <titel>Main Login Page</titel> <style type="text/css"> </style> </head> <body> <div id="loginform"> <form method ="post" action= <?php $host = "localhost"; $username = "root"; $password = ""; $db_name = "test"; $tbl_name = "members"; mysql_connect ($host, $username, $password) or die ("the server made a boo boo"); mysql_select_db ($db_name) or die (mysql_error () ); $myusername = $_POST ['myusername']; $mypassword = $_POST ['mypassword']; $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows ($result); if($count ==1) { session_register ("myusername"); session_register ("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> <label for="username">Username:</label> <input type"text" name="myusername" id="username" /> <label for="password">Password:</label> <input type="password" name="mypassword" id="password" /> <input type="submit" name="submit" value="Login" /> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985398 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Ok I see.. <?php $message = ''; if (isset($_POST['submit'])) { $host = "localhost"; $username = "root"; $password = ""; $db_name = "test"; $tbl_name = "members"; mysql_connect ($host, $username, $password) or die ("the server made a boo boo"); mysql_select_db ($db_name) or die (mysql_error () ); $myusername = $_POST ['myusername']; $mypassword = $_POST ['mypassword']; $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows ($result); if($count ==1) { session_start(); $_SESSION['myusername'] = $_POST['myusername']; $_SESSION['logged_in'] = true; header("location:login_success.php"); } else { $message = "Wrong Username or Password"; } } ?> <html> <head> <titel>Main Login Page</titel> <style type="text/css"> </style> </head> <body> <div id="loginform"> <form method ="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <label for="username">Username:</label> <input type"text" name="myusername" id="username" /> <label for="password">Password:</label> <input type="password" name="mypassword" id="password" /> <input type="submit" name="submit" value="Login" /> <br/> <?php echo $message; ?> </form> </div> </body> </html> Might work a little better for your main script Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985400 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 Buddski omg! that its.. but now i got another error... :S Firefox cant find the file at C:/wamp/www/<?php echo $_SERVER['REQUEST_URI']; ?>. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985402 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Ok just replace that <?php echo $_SERVER['REQUEST_URI']; ?> with the name of your file like action="somescript.php" Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985403 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 Ok just replace that <?php echo $_SERVER['REQUEST_URI']; ?> with the name of your file like action="somescript.php" that diddnt work. i got this error Firefox cant find the file at: /C:/wamp/www/header("location:login_success.php");. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985410 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Well the error has changed so the last fix did work.. Its now trying to redirect you but its not working.. change header("location:login_success.php"); to header("Location: login_success.php"); Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985412 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 Well the error has changed so the last fix did work.. Its now trying to redirect you but its not working.. change header("location:login_success.php"); to header("Location: login_success.php"); Login was Successful THANK YOU!!!! Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985413 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 one other thing.. On your login success page.. change if(!session_is_registered(myusername)) { to if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) { just a little bit better than your current method.. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985417 Share on other sites More sharing options...
Ungerbla Posted December 29, 2009 Author Share Posted December 29, 2009 Buddski emn.. just one thing.. it dosent check the database.. anyone can enter.. infact you dont even have to enter something in the Username and Password boxes.. it still says success... Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985419 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 I see that. change $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows ($result); if($count ==1) { session_start(); $_SESSION['myusername'] = $_POST['myusername']; $_SESSION['logged_in'] = true; header("location:login_success.php"); } else { $message = "Wrong Username or Password"; } } to $sql = "SELECT * FROM $tbl_name WHERE username='$myusername'"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { $data = mysql_fetch_assoc($result); if ($data['password'] == $mypassword) { session_start(); $_SESSION['myusername'] = $_POST['myusername']; $_SESSION['logged_in'] = true; header("Location: login_success.php"); } else { $message = 'Username/Password combination incorrect'; } } else { $message = 'Username/Password combination incorrect'; } You may also want to look into hashing your passwords too. Look at md5 in the php manual. Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985421 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 You should also check to see if there is values in $_POST['myusername'] and $_POST['mypassword'] aswell Quote Link to comment https://forums.phpfreaks.com/topic/186581-my-login-wont-work/#findComment-985422 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.