Problem with this simple login.php


<?php error_reporting(E_ALL); session_start(); $host="localhost"; $username="root"; $password="alexi"; $db_name="users"; $tbl_name="accounts"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name") or die("cannot select DB"); $username=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM `accounts` WHERE `username`='".$username."' and `password`='".$password."'"; $result=mysql_query($sql) or die ( mysql_error () ); $count=mysql_num_rows($result); if($count==1) { $_SESSION['username'] = $username; if(isset($_SESSION['username'])) { echo 'You are logged in'; } } else { echo 'incorrect'; } ?>


When I try to login, It reads “Incorrect”. I’m entering the correct password though, so I’m not sure why it’s not working…

Obviously your query returns 0 records or more than 1 record. Are you using POST method in your login form?
You may also need to check your records in database table.

never mind, I got it! the problem was i had an encryped password, and it wasnt asking for encrypted password in the login.php

btw if you dont know the answer dont post :stuck_out_tongue:

btw if you dont know the answer dont post
You come here to ask help, and I tried to help. Where in your post you mentioned that passwords are encrypted in your database?
Sponsor our Newsletter | Privacy Policy | Terms of Service