I'm making a PHP and MySQL RPG game, and my changeEquipment page is not working. I'm getting these errors:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'devinfa1'@'localhost' (using password: NO) in /home/devinfa1/public_html/spellsword/changeEquipment.php on line 21
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/devinfa1/public_html/spellsword/changeEquipment.php on line 21
Warning: mysql_query() [function.mysql-query]: Access denied for user 'devinfa1'@'localhost' (using password: NO) in /home/devinfa1/public_html/spellsword/changeEquipment.php on line 27
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/devinfa1/public_html/spellsword/changeEquipment.php on line 27
Here's my code:
<?php
// Get commonFunctions.php
require_once('commonFunctions.php');
// Start the session and connect to the database
session_start();
$con = mysql_connect("localhost","devinfa1_user","dbpass");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("devinfa1_spellsword", $con);
// If logged in
if(isset($_SESSION['account_name'])) {
// If form is submitted
if(isset($_POST['submit']) || isset($_POST['submit_x'])) {
// If the hero has more than one weapon
if(hero_has_multiple_weapons()) {
// Set new weapon
mysql_query("UPDATE Hero_Weapons SET active_weapon = TRUE WHERE HW_hero_id =
(SELECT hero_id FROM Heroes WHERE hero_name = '$_SESSION[hero_name]')
AND HW_item_id = (SELECT item_id FROM Items WHERE item_name = '$_POST[weapon]')");
// Unset previous weapon
if(isset($_SESSION['hero_name'])) {
mysql_query("UPDATE Hero_Weapons SET active_weapon = FALSE WHERE HW_hero_id =
(SELECT hero_id FROM Heroes WHERE hero_name = '$_SESSION[hero_name]')
AND HW_item_id = (SELECT item_id FROM Items WHERE item_name = '$_SESSION[weapon_name]')");
}
}
// Close the database connection
mysql_close($con);
?>
So, the PHP should be connecting to my databse using the devinfa1_user
username and dbpass
password, but it's apparently trying to use the devinfa1
username with no password.
I have no idea why this is the case, because I have the exact same connection code and an update statement on my changeHero page and it works perfectly. Any ideas?