sketzzz1 Posted February 5, 2012 Share Posted February 5, 2012 I have set up a database using myPHPadmin, I have created the following code: <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("127.0.0.1","root","password") or die("Couldnt connect to database"); mysql_select_db("login") or die ("Couldnt find database"); $query = mysql_query("SELECT * FROM users WHERE username ='$username'"); $numrows = mysql_num_rows ($query); if($rumrows != 0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { echo "Login successful. <a href='members.php'> Click here to enter memebers area </a>"; $_SESSION['username']=$dbusername; } else echo "Incorrect password"; } else die ("Username does not exist"); } else die ("Please enter a username and password"); ?> Even though the database is set up when i try and enter the username for the log in page and password, it says the username does not exist? I dont understand why when it is in the database? Please help! MOD EDIT: . . . BBCode tags added. Quote Link to comment https://forums.phpfreaks.com/topic/256468-creating-a-log-in-page-using-php/ Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2012 Share Posted February 5, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Have you var_dumped all the the values to make sure they're identical? There's no logic in that code to determine if the query runs successfully or not. Do you have php's error reporting set up with the following directives in your php.ini file? error_reporting = -1 and display_errors = On ? Quote Link to comment https://forums.phpfreaks.com/topic/256468-creating-a-log-in-page-using-php/#findComment-1314786 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.