I have some code that currently works but I need to turn it into a function in my users class. This is the SQL which I want to turn in to a function
if(isset($_POST['teams'])){
$stmt = $DB_con->prepare("UPDATE users SET team_id= '$playerteam' WHERE user_id = $user_id ");
$stmt->execute();
}
if(isset($_POST['leaveteam'])){
$stmt = $DB_con->prepare("UPDATE users SET team_id= 0 WHERE user_id = $user_id ");
$stmt->execute();
}
$stmt = $DB_con->prepare("SELECT * FROM teams
INNER JOIN users
ON teams.id=users.team_id
ORDER BY team_name ASC");
$stmt->execute();
$teamRow=$stmt->fetchall(PDO::FETCH_ASSOC);?>
I tried this but I could not get the function to update the team_id
public function joinTeam($playerteam)
{
if(isset($_POST['teams'])){
$stmt = $DB_con->prepare("UPDATE users SET team_id= '$playerteam' WHERE user_id = $user_id ");
$stmt->execute();
}
Would anyone be able to help me turn this sql in to a function, thanks.