FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP and MySQL login...Help





Asap170
Okay well I try to login to my login system, but it won't let me. Here is my code.

Code:
// Connect to MySQl
    mysql_connect("$hostname", "$username", "$password") or die(mysql_error());

// Connect to your MySQL database
    mysql_select_db("$db_name") or die(mysql_error());

// Gather the username and password sent from the login page
    $login_user = $_POST['user'];
    $login_pass = $_POST['pass'];     

// Protect MySQL injection
    $login_user = stripslashes($login_user);
    $login_pass = stripslashes($login_pass);
    $login_user = mysql_real_escape_string($login_user);
    $login_pass = mysql_real_escape_string($login_pass);
   
        // Encrypt password
            $encrypted_password = md5($login_pass);

    $sql="SELECT * FROM $tbl_name WHERE username='$login_user' and password='$login_pass'";
    $result=mysql_query($sql);

// Mysql_num_row is counting table row
    $count = mysql_num_rows($result);

// If result matched $login_user and $login_pass, table row must be 1 row
    if($count == 1){
        // Register $login_user, $login_pass and redirect to file "login_success.php"
            session_register("$login_user");
            session_register("$login_pass");
            header("location:./login_success.php");
        } else {
            echo "Wrong Username or Password";
}

ob_end_flush();
?>


I checked my MySQL db and made sure I was using the correct credentials but I got "Wrong Username or Password" Any help would be appreciated and I believe my error is somewhere in the last 15 lines.
badai
try put this before Connect to MySQl :

Code:
echo $hostname."<br />".$username."<br />".$password
jmraker
I would output the value of $sql, if the statement looks ok then use phpMyAdmin to run that sql statement. If the sql statement returns 0 records, check out the record that you think it should match to make sure everything matches. If it returns 2+ records, you'll need to delete one or change the program.

If the username and password are blank in $sql. Then try using $_REQUEST or $_GET instead of $_POST

Code:
$sql="SELECT * FROM $tbl_name WHERE username='$login_user' and password='$login_pass'";
var_dump($sql);
$result=mysql_query($sql);


Edit. I didn't notice the md5 hash. If the hash is wrong take out the mysql_real_escape_string for the password. It can add slashes that might not have been in the original generated md5 hash.
Asap170
Well I have actually fixed my error....I had user_id on my other page. I felt really stupid, but now my sessions are wacked and it isn't recognizing there is a session..should I make a cookie instead?
sonam
This is what is writing on php.net.
Quote:
Use of session_register() is deprecated


Instead you can use
Code:
$_SESSION["username"] = $login_user;
$_SESSION["pass"] = $login_pass;


Sonam
jmraker
You can put all your initialization stuff in one php file so getting the session started can use the same settings for every program.

PHP sessions set a PHPSESSID cookie which stores part of a name to a temporary file with session data, it's possible that your programs are sending that cookie diffrently enough that the browsers are keeping 2+ instances of the session id where one is one where you're logged in, and the other is a new one. Usually the difference is in the path or domain name.
Aredon
sonam wrote:
This is what is writing on php.net.
Quote:
Use of session_register() is deprecated


Instead you can use
Code:
$_SESSION["username"] = $login_user;
$_SESSION["pass"] = $login_pass;


Sonam

Don't forget session_start(); or those superglobals won't exist. Smile
Asap170
Well I am using the depreciated way of doing it x.x I got that working from my friend that knows PHP. Anyways I think everything is all good. My login runs basically perfectly on FireFox but IE...Well that's a whole different story. Thanks for everyone that helped.
Related topics
PHP, MySQL...
ASP +PHP+MySQL Tutorials
what is your php mysql apache installer package
Need some php/mysql dlls
The Basics (php, mysql etc)
What is useful way in this php+mysql problem?
PHP/Mysql - beginner!
A very good PHP MySQL Tutorial
Setup php,mysql and others...
Link PHP/Mysql with Outlook Express
Free PHP/MySQL login script
php-mysql source code
portable php+mysql
Simple PHP Login Script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.