I created a website on Windows using PHP, MySQL and one Line of JS, and tested it with XAMPP. Works perfectly. If I load this page on my PI now, it doesn't work anymore. The php script stop working. PHP is up-to-date. I can't update MariaDB because the latest available version for the PI is 10.3.23-MariaDB-0+deb10u1.
Both times I get the error message :
PHP Notice: Undefined index: SERVER_NAME in /var/www/test/inc/functions.php on line 5
PHP Fatal error: Uncaught mysqli_sql_exception: No index used in query/prepared statement (null) in /var/www/test/inc/functions.php:497
Stack trace:
#0 /var/www/test/inc/functions.php(497): mysqli_stmt_execute()
#1 /var/www/test/opener.php(8): checkCurrentTimer()
#2 {main}
thrown in /var/www/test/inc/functions.php on line 497
using mysqli_report(MYSQLI_REPORT_OFF);
this error is no longer displayed.
What is my error? The databases on the PI and my PC are identical (exported from the PC, imported into the PI and checked).
<?php
//Looks like the next line causes the problem
if (checkCurrentTimer(0)){
echo '<div class="col">
<form method="post" action="'.$_SERVER['PHP_SELF'].'" style="margin-left:auto;margin-right:auto;display:flex;">
<input type="number" name="number" placeholder="Sec" style="max-width:60px"><p> </p>
<button type="submit" class="btn btn-block btn-dark" value="Zeitschaltung" name="Zeitschaltung" style="font-size:18px;">Zeitschaltung</button>
</form>
</div> ';
}else{
if(strtolower(checkCurrentTimer(1)) == strtolower($_SESSION['session_user'])){
?>
<script src="/inc/js/jquery-3.5.1.js"></script>
<script type="text/javascript">
<!-- setTimeout("document.location.reload();",1000); -->
var initialTime = <?php echo timeleft($_SESSION['session_user']);?>;
var seconds = initialTime - 1;
function timer() {
var remainingSeconds = seconds;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('timer').innerHTML = "Dein Timer läuft noch <br>" +remainingSeconds+ "<br>Sekunden";
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('timer').innerHTML = "Completed";
} else {
seconds--;
}
}
var countdownTimer = setInterval('timer()', 1000);
</script>
<div class="col">
<form id="timer" class="btn btn-block btn-dark" name="return" style="color:green;font-size:14px;width:200px;margin-left:auto;margin-right:auto">
Dein Timer läuft noch <br> <?php echo timeleft($_SESSION['session_user']);?><br> Sekunden
</form>
</div>
<?php
}else{
echo '
<div class="col">
<form class="btn btn-block btn-dark" name="return" style="color:orange;font-size:14px;width:200px;margin-left:auto;margin-right:auto"">
Ein Timer läuft aktuell
</form>
</div>
';
}
}
?>
The function:
function checkCurrentTimer($arg){
include 'db.php';
switch($arg){
case 0:
$sql = "SELECT COUNT(*) AS counts FROM timer;";
$stmt = mysqli_stmt_init($connection);
if (!mysqli_stmt_prepare($stmt, $sql)){
// Leitet auf die Einstellungsseite weiter und meldet das ein Fehler aufgetreten ist
mysqli_stmt_close($stmt);
mysqli_close($connection);
header("Location: ../module/oneklick.php?error=sqlerror&m=54");
exit();
}else{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result);
$counts = (int)$row['counts'];
if($counts == 0 ){
mysqli_stmt_close($stmt);
mysqli_close($connection);
return true;
}elseif($counts > 0 ){
mysqli_stmt_close($stmt);
mysqli_close($connection);
return false;
}
}
break;
case 1:
$sql = "SELECT user FROM timer";
$stmt = mysqli_stmt_init($connection);
if (!mysqli_stmt_prepare($stmt, $sql)){
// Leitet auf die Einstellungsseite weiter und meldet das ein Fehler aufgetreten ist
mysqli_stmt_close($stmt);
mysqli_close($connection);
header("Location: ../opener.php?error=sqlerror&m=55");
exit();
}else{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result);
$user = $row['user'];
if(empty($row['user'])){
$user = "%Empty%" ;
}
mysqli_stmt_close($stmt);
mysqli_close($connection);
return $user;
}
break;
default:
header("Location: ../opener.php?error=sqlerror&m=55");
exit();
}
}
Pi phpmyadmin: https://prnt.sc/uq5rgw
XAMPP phpmyadmin: https://prnt.sc/uq5rur
DB table timer structure: https://prnt.sc/uq5scx