At the start of the document, i call include database.php , which contains
$database = new mysqli('localhost', 'root', 'root', 'dbname', 3306);
However, the $database variable doesnt seem to exist when i try to update db info via a function, so i have to call it again
Is there any solution to this?
function code:
<?php
include 'database.php';
?>
. . .
<?php
function roll() {
$bet= $_POST["bet"];
$_SESSION['dice1']=rand(1,6);
$_SESSION['dice2']=rand(1,6);
$total=$_SESSION['dice1']+$_SESSION['dice2'];
if($total==2) $win=$bet*2;
else if($total==3 || $total==4) $win=0;
else if($total==10 || $total==11) $win=$bet;
else if($total==12) $win=$bet*4;
else if($total==0) $win=0;
else $win=$bet-(2*$bet);
// $database = new mysqli('localhost', 'root', 'root', 'dbname', 3306);
$database->query("UPDATE users SET balance=balance+'$win' WHERE name='$_SESSION[username]'");
}