I have a prepared statement that will insert an entry into the database. The statement works fine and inserts entries. I wrap the statement in a function, call the function, and it no longer inserts into the database. Is there an issue with calling these statements from a function? Side note...my end goal is to actually put this function in a class as a method. I was attempting that, and began troubleshooting and have determined the error begins when putting in a function. My next step is to move this into a class. Is there anything else in my code that would prevent that from being possible?
<?php
include 'main_connection.php';
function add() {
$stmt = $mysqli->prepare("INSERT INTO user (name) VALUES (?)");
$stmt->bind_param('s',$name);
$name = "test";
$stmt->execute();
$stmt->close();
}
add();
?>