Need help, something's wrong with database?

The problem is, when i put in the right username and password, and i know that its in the table, i looked, it says Incorrect password, try again.
Can someone fix this or give me a new code i could use for login?

<?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("gf") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = $cQuery="SELECT * FROM users WHERE user='".$username."' AND pass='".$pass."'"; while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: forums.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['txtEmail'] = addslashes($_POST['txtEmail']); } $check = mysql_query("SELECT * FROM users WHERE user = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: forums.php"); } } } else { // if they are not logged in ?>


<?php }

[size=99px]edit Q1712: changed [code] to [php][/size]

$info is not set (u would have recogniced that, if u had used error_reporting(E_ALL))


$check = mysql_query(“SELECT * FROM users WHERE user = '”.$_POST[‘username’]."’")or die(mysql_error());
$info = mysql_fetch_assoc($check);

//Gives error if user dosen’t exist
if (!$info) {
die(‘That user does not exist in our database.>’);

P.S.: please use [php] instead of [code] for php-code

That fixed the password thing, but the redirect isnt working, it doesnt send me to forums.php

plz use error_reporting(E_ALL) while developing!

maybe there is some space before ‘<?php’.

See the link in my signature for help on debugging code.

Sponsor our Newsletter | Privacy Policy | Terms of Service