I do have a debugging code on the top of my page but that doesn't show anything due to it being a logic error (as I was told
I am logging in with the playerid of 1 from the database image below so I am using a user that has a character.
My table from Database

ERROR from my Apache Log
PHP Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\\wamp\\www\\characterselected.php on line 26
ERROR that shows on my page
There has been an error during your login. Character not found for your account. Please log in again.
Errored Line
Code: Select all
//check to make sure that character id actually belongs to player
$result = mysqli_fetch_assoc(mysqli_query($db, "SELECT cname FROM playercharacter WHERE playercharacterid='$playercharacterid' and playerid='$playerid'"));
Code: Select all
<?php
$debug = true; // switch to false once you finished your game :)
define("DEBUG", $debug); // define a global usable DEBUG constant ( you can use it on all your pages after it is defined )
error_reporting(E_ALL); // tells PHP to report ALL errors possible ( notices, warnings, fatal errors et cetera )
ini_set('display_errors', $debug); // this command actually forces PHP to display them, what good is reporting if they`re not going to be displayed?
?>
<?php
include 'connect.php';
session_start();
$exitScript = 0;
$username = $_SESSION['name'];
if(!$username) {
echo "could not get username";
exit;
}
$playerid = $_SESSION['playerid'];
if(!$playerid) {
echo "could not get playerid";
exit;
}
$playercharacterid = $_GET['pcid'];
if(!$playercharacterid) {
echo "could not get playercharacterid";
exit;
}
if (!$_SESSION['name']) {
$exitScript = 1;
}
?>
<?php
if ($exitScript == 0){
//check to make sure that character id actually belongs to player
$result = mysqli_fetch_assoc(mysqli_query($db, "SELECT cname FROM playercharacter WHERE playercharacterid='$playercharacterid' and playerid='$playerid'"));
if (!$result) {
echo "There has been an error during your login. Character not found for your account. Please log in again.<br /><br />";
$_SESSION = array();
echo "<a href='index.php'>Log in</a>";
exit();
}
//process successful player/character login
if (!isset($_SESSION['playercharacterid'])) {
$_SESSION = $playercharacterid;
}
echo "You have successfully logged in!<br /><br />";
echo "<a href='index.php'>Welcome to Neohazard!</a>";
} else {
echo "You are not logged in. Please go back and log in.<br />";
echo "<a href='index.php'>Home Page</a>";
}
?>
</div>