Error checking login data Access denied for user 'username'@'localhost' (using password: NO)
My Databse Code
<?php
$conn = mysql_connect('localhost', 'root','' );
$db = mysql_select_db('toys');
if(!$db){
echo mysqli_error($db);
return;
} ?>
Error I get is user 'username'@'localhost' (using password: NO)
My welcome.php
<?php
include('1.php');
include_once('database.php');
include('sidebar.php');
$uname=$_SESSION['username'];
$s=mysql_query("select center from users where username='$uname'");
$df=mysql_fetch_array($s);
$_SESSION['center']=$df['center'];
//$_SESSION['vid']=$_REQUEST['id'];
?>
My user.php
<? ob_start(); ?>
<?php
if (isset($_GET['msg']))
$msg = $_GET['msg'];
$msg="User Login Here";
if(isset($_POST['login']) && $_POST['login']!=''){
include_once('database.php');
$username = $_POST['username'];
$pass = $_POST['pass'];
$cent =$_POST['center'];
if($username=='')
{
$msg.= '<br>Please enter username';
}
if($pass=='')
{
$msg.= '<br>Please enter password';
}
if($cent=='')
{
$msg.= '<br>Please enter center';
}
if($username!='' && $pass!='' && $cent!='')
{
$username = mysql_real_escape_string( $username );
$password = mysql_real_escape_string( md5($pass) );
$center = mysql_real_escape_string($cent);
$res = mysql_query("SELECT * FROM users WHERE (username='$username' and password='$password' and center='$center' ) ");
if(!$res){
echo 'Error checking login data <br/>' .mysql_error();
return;
}
var_dump($row = mysql_fetch_row($res));
// exit();
if( $row > 0 ) {
session_start();
$_SESSION['username'] = $username;
header('location:home.php');
}
else{
$msg= "<h1>Invalid username or password</h1>";
}
?>
One more Question WHY it is working fine on wamp
Once I put it online it show that error. I tried everything but no change. my user.php shows up with login credentials but after login instead of moving too home .php it comes back to user.php with css but no details but a blank page with error
checked everything but no answer
mysql_*API. Usemysqli_*orPDO