porkypie Posted January 1, 2013 Share Posted January 1, 2013 (edited) Hey, I'm trying to use a tutorial to make a login for my website using this tutorial: http://www.phpeasyst...om/phptu/6.html I'm getting the following error when I try to login:Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\.........................\www\login.php on line 9cannot connect The fat underlined line is line 9 This is the code I am using: <?php$host="localhost"; //$username="root"; //$password=""; //$db_name="westpop"; //$tbl_name="leden"; //mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");$myusername=$_POST['myusername'];$mypassword=$_POST['mypassword'];$count=mysql_num_rows($result);if($count==1){session_register("myusername");session_register("mypassword");header("location:login_succes.php");}else {echo "Wrong Username or Password";}?> Anyone able to tell me what i do wrong? Thanks in advance! Porkypie Edited January 1, 2013 by porkypie Link to comment Share on other sites More sharing options...
will71110 Posted January 1, 2013 Share Posted January 1, 2013 Get rid of the quotes => mysql_connect($host, $username, $password) or die("cannot connect"); Link to comment Share on other sites More sharing options...
porkypie Posted January 2, 2013 Author Share Posted January 2, 2013 Thanks for the help. It seems something else is wrong with my code. When i try to log in now i get the following message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\.........................\www\login.php on line 15Wrong Username or Password. This is line 15:$count=mysql_num_rows($result); how do i fix my problem this time? Porkypie Link to comment Share on other sites More sharing options...
Labtec Posted January 2, 2013 Share Posted January 2, 2013 (edited) For one you haven't got a query. You're not checking the input against any records. You're also passing $result to mysql_num_rows(), which hasn't been set. Try something like: $host="localhost"; //$username="root"; //$password=""; //$db_name="westpop"; //$tbl_name="leden"; // mysql_connect($host, $username, $password)or die("cannot connect");mysql_select_db($db_name)or die("cannot select DB"); $myusername=$_POST['myusername'];$mypassword=$_POST['mypassword']; $result = mysql_query("SELECT * FROM $tbl_name WHERE username='{$myusername}' AND password='{$mypassword}'"); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:login_succes.php"); } else { echo "Wrong Username or Password"; } This is assuming your table field for the username and pass is 'username' and 'password'. If it isn't just change the query to suit the table field names. Regards, Lab. Edited January 2, 2013 by Labtec Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now