I have a landing page in which there is an include of a php module. I know it is executing because it is delivering echo output to page. However, the mysql query that seems to work in the authentication module, when ported and replacing code in this included code generates the following nasty-grams.

Warning: mysql_query() [function.mysql-query]: Access denied for user 'acunishi'@'localhost' (using password: NO) in /home1/acunishi/public_html/go/auth/birthdays_holidays-greetingsv2.php on line 29

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home1/acunishi/public_html/go/auth/birthdays_holidays-greetingsv2.php on line 29
Invalid query: Access denied for user 'acunishi'@'localhost' (using password: NO)

Any thoughts?

Here is the beginning of the code with name of database, table, username and password eliminated for security.

<?php
session_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
$dblink = mysqli_connect($host,$username, $password,$db_name);
//mysqli_select_db("$db_name")or die("cannot select DB");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysqli_real_escape_string($dblink,$myusername);
$mypassword = mysqli_real_escape_string($dblink,$mypassword);
//end of setup and database open

$result3 = mysql_query("SELECT nickname, announce, lastlogin from '$db_name'.'$tbl_name' WHERE '$tbl_name'.'username' = '$myusername'");
if (!$result3) {
die('Invalid query: ' . mysql_error());
}


$num_rows = mysql_num_rows($result3);
$row3 = mysql_fetch_assoc($result3);
echo " \n <br>";
echo $row3['nickname'.' '.'announce'.' '.'lastlogin'];
echo " ";
echo " \n";


- Show quoted text -