desperately need some help here. I've recently gone back to a game I had developed a few years ago now that I've got some free time. When I left it all the Php/mysqli code was working perfectly fine. No issues at all.
However, now it is not. For example, when I try to login to the game it I'm getting username and/or password is invalid. Now, obviously I'm using a known username/password.
I've found that it works fine on php5.1 but not on any higher version. I figured I'd have to rewrite the code to suit php7 but I'm having problems with that.
I've tested my code on various online checkers with various php7 versions and I get this error every time... Fatal error: Uncaught Error: Class 'mysqli' not found in ... but no syntax errors, no deprecated code.
I have confirmed with my host that mysqli is installed (cpanel) so clearly that's not the issue.
I've also checked using this code snippet ...
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'you dont have';
} else {
echo 'you have!';
}
I have!
I've also run checks that there is a database connection. And when I check the php error log in cpanel I'm not getting any errors at all.
So what's going on? It's as if the data isn't being retrieved from the database. I used to be able to test by changing all the POST syntax to GET so I could manually login via the url but that doesn't work either now.
Any help is much appreciated and thanks in advance.
My login script:
<?php
$dbhost = 'localhost';
$dbuser = 'me';
$dbpass = 'xxxx';
$dbname = 'me_again';
$nameTable = 'table';
$string = '';
$conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if($conn->connect_error) {
$string = 'valid=8';
} else {
$username = '';
$userpass = '';
$loginRequest = '';
if (isset($_POST['username'])) {
$username = $_POST['username'];
}
if (isset($_POST['userpass'])) {
$userpass = $_POST['userpass'];
}
if (isset($_POST['loginRequest'])) {
$loginRequest = $_POST['loginRequest'];
}
if($loginRequest == "login") {
if ($s = mysqli_prepare($conn, "SELECT `usersalt` FROM `{$nameTable}` WHERE `username`=? LIMIT 1")) {
mysqli_stmt_bind_param($s, "s", $username);
mysqli_stmt_execute($s);
mysqli_stmt_store_result($s);
if (1 == mysqli_stmt_num_rows($s)) {
mysqli_stmt_bind_result($s, $usersalt);
// fetch only 1 result
mysqli_stmt_fetch($s);
if ($s2 = mysqli_prepare($conn, "SELECT `username`,`cat1`,`cat2`,`cat3`,`cat4`,`cat5`,`cat6`,`userscore`,`userplayed`,`correct` FROM `{$nameTable}` WHERE `username`=? AND `userpass`=? ")) {
$hashedpass = sha1($usersalt . $userpass);
mysqli_stmt_bind_param($s2, "ss", $username, $hashedpass);
mysqli_stmt_execute($s2);
mysqli_stmt_store_result($s2);
if (1 == mysqli_stmt_num_rows($s2)) {
mysqli_stmt_bind_result($s2, $res_name, $res_cat1, $res_cat2, $res_cat3, $res_cat4, $res_cat5, $res_cat6, $res_score, $res_played, $res_correct );
// fetch only 1 result
mysqli_stmt_fetch($s2);
header('Content-Type: text/xml');
echo "<?xml version='1.0'?>";
echo "<".$nameTable.">";
echo "<player>";
echo "<username>".$res_name."</username>";
echo "<cat1>".(int)$res_cat1."</cat1>";
echo "<cat2>".(int)$res_cat2."</cat2>";
echo "<cat3>".(int)$res_cat3."</cat3>";
echo "<cat4>".(int)$res_cat4."</cat4>";
echo "<cat5>".(int)$res_cat5."</cat5>";
echo "<cat6>".(int)$res_cat6."</cat6>";
echo "<userscore>".(int)$res_score."</userscore>";
echo "<userplayed>".(int)$res_played."</userplayed>";
echo "<correct>".(int)$res_correct."</correct>";
}
mysqli_stmt_close($s2);
} else {
$msg = ((is_object($conn)) ? mysqli_error($conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
$string = 'valid=0';
}
} else {
$msg = ((is_object($conn)) ? mysqli_error($conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
$string = 'valid=1';
}
mysqli_stmt_close($s);
} else {
$msg = ((is_object($conn)) ? mysqli_error($conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
$string = 'valid=2';
}
}
}
$conn->close();
echo $string;
?>