I have this PHP script where I make an insert query in a mysql DB, what I do is declare a mysqli object globally and then from a function make the insert, but since the insert function gives me an error, it tells me that recognizes the $ mysqli object
$servidor = "localhost";
$usuario = "root";
$password ="xxxx";
$basededatos = "xxxx";
$mysqli = new mysqli($servidor, $usuario, $password, $basededatos);
if ($mysqli->connect_errno) {
echo "Falló la conexión con MySQL: (".$mysqli->connect_errno.") ".$mysqli->connect_error;
}
function insertar($name,$dni) {
$cadena = "update users set xxxxx";
$mysqli->query($cadena);
}