PHP: Cookies funktionieren nicht?

/cookie/deny.php

<?php
setcookie("deny", 1, time() + (3600*24*7));
setcookie("userid", 1, time() - 1);
?>

/cookie/accept.php

<?php
$time = time();
$userid = $time.rand(1,999);

setcookie("userid", $userid, $time + (3600*24*7));
setcookie("deny", 1, $time-1);

if(isset($_COOKIE["userid"])) {
		$db = mysqli_connect("127.0.0.1","root","","Cookies");
		set_cookie_info($db,$_COOKIE["userid"]);
		mysqli_close($db);
		echo "@set";
}

function set_cookie_info($db,$userid) {

	$useragent = $_SERVER["HTTP_USER_AGENT"];
	$data = get_browser($useragent);
	$time = time();
	
	$browser = $data -> browser;
	$version = $data -> version;
	$device_type = $data -> device_type;
	$os = $data -> platform;
	$join = $time;
	$left = $time;
	$calls = 1;
	
	$db -> query(
	"INSERT INTO `users` 
	(`UserID`, `Browser`, `Version`, `DeviceType`, `OS`,
	`Join`, `Left`, `Calls`, `UserAgent`) 
	VALUES(
	'".$userid."',
	'".$browser."',
	'".$version."',
	'".$device_type."',
	'".$os."',
	'".$join."',
	'".$left."',
	'".$calls."',
	'".mysqli_real_escape_string($db,$useragent)."'
	)");
}
?>

/cookie/update.php

<?php
function update_cookie_info($userid) {
	var_dump(
	$db -> query(
	"UPDATE `users` 
	SET `Calls`=`Calls`+1, `Left`='".time()."' 
	WHERE `UserID`='".$userid."'")
	);
}

if(isset($_COOKIE["userid"])) {
	$db = mysqli_connect("127.0.0.1","root","","Cookies");
	update_cookie_info($db,"userid");
	mysqli_close($db);
}
?>

/index.php

<?php 
require "cookie/update.php";
if(!isset($_COOKIE["deny"]) and !isset($_COOKIE["userid"])):?>
<div class="cookie-box">
Wir verwenden Cookies
<button id="cookie_deny" class="cookie-deny">Ablehnen</button>
<button id="cookie_accept" class="cookie-accept">Alles Klar</button>
</div>
<?php endif;?>
<script>
document.getElementById("cookie_accept").onclick=function() {
	if(window.XMLHttpRequest){
	xmlhttp=new XMLHttpRequest();
	}
	else{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET","/cookie/accept.php",false);
	xmlhttp.send();
	this.parentNode.classList.add("hide");
}

document.getElementById("cookie_deny").onclick=function() {
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET","/cookie/deny.php",false);
	xmlhttp.send();
	this.parentNode.classList.add("hide");
}
</script>

Das sind die bisherigen Dsteien die ich verwende.

Eigentlich müsste doch alles perfekt funktionieren, aber es funktioniert nicht wirklich etwas, außer dem Eintragen in die Datenbank... Bin mal wieder ratlos...

Danke im Voraus :)

PC, Computer, Internet, Browser, Technik, sql, Webseite, Programmieren, Cookies, Code, Datenbank, MySQL, PHP, Technologie, Variablen, MariaDB
Warning: mysqli::query() expects at most 2 parameters?

Warning: mysqli::query() expects at most 2 parameters, 3 given in /Pfad on line 52

NULL

<?php
 
$db = mysqli_connect("127.0.0.1","root","","Cookies");
$time = time();
$userid = $time.rand(1,999);


setcookie("userid", $userid, $time + (3600*24*7));
setcookie("listed", 0, $time + (3600*24*7));


if(isset($_COOKIE["userid"])) {
	if($_COOKIE["listed"]==0) {
		//$_COOKIE["listed"]=1;
				setcookie("listed", 1, $time + (3600*24*7));
		// Datenbankwerte eintragen
		set_cookie_info($db,$_COOKIE["userid"]);
		echo "@set";
	}
	else{
		update_cookie_info($db,$_COOKIE["userid"]);
		echo "@update";
	}
}


function set_cookie_info($db,$userid) {
	$useragent = $_SERVER["HTTP_USER_AGENT"];
	$data = get_browser($useragent);
	$time = time();
	
	$browser = $data -> browser;
	$version = $data -> version;
	$device_type = $data -> device_type;
	$os = $data -> platform;
	$join = $time;
	$left = $time;
	$calls = 1;
	
	var_dump(
	$db -> query(
	"INSERT INTO `users` 
	(`UserID`, `Browser`, `Version`, `DeviceType`, `OS`,
	`Join`, `Left`, `Calls`, `UserAgent`) 
	VALUES(
	'".$userid."',
	'".$browser."',
	'".$version."'
	'".$device_type."',
	'".$os."',
	'".$join."',
	'",$left,"',
	'".$calls."',
	'".mysqli_real_escape_string($db,$useragent)."'
	)"));
}


function update_cookie_info($db,$userid) {
	$time = time();
	var_dump(
	$db -> query(
	"UPDATE `users` 
	SET `Calls`=`Calls`+1, `Left`='".$time."' 
	WHERE `UserID`='".$userid."'")
	);
}
?>

Ich verstehe den Fehler nicht, wenn ich den Querystring kopiere und manuell ausführe gehts aber.

Danke im Voraus :)

ps. bräuchte ich dafür nen Cookiehinweis, Datenschutzblatt oder Cookieablehnungsmöglichkeiten?

PC, Computer, Datenschutz, Browser, Programm, sql, HTML, Programmieren, Cookies, Datenbank, MySQL, PHP, MariaDB, OOP Programmierung