Hello im using GitHub to help build me a site because i have minimal experience with coding, I have my manager_id set to NOT NULL in my database and i keep getting this error
Error: Could not create team. Column 'manager_id' cannot be null
Here is the code github keeps giving to clear the error but it doesn't seem to work.
// Handle team creation
if (isset($_POST['create_team'])) {
// Validate form data
$name = trim($_POST['teamname']);
$tag = trim($_POST['tag']);
if (empty($name)) {
$errors[] = 'Team name is required.';
}
if (empty($tag)) {
$errors[] = 'Tag is required.';
}
if (empty($errors)) {
// Insert new team into the database
$sql = "INSERT INTO teams (teamname, tag, manager_id) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 'ssi', $name, $tag, $_SESSION['user_id']);
$result = mysqli_stmt_execute($stmt);
if ($result === false) {
$errors[] = 'Error: Could not create team. ' . mysqli_error($conn);
} else {
$team_id = mysqli_insert_id($conn);
// Add the user to the team
$sql = "INSERT INTO players (userid, playername, team_id) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 'isi', $_SESSION['user_id'], $_SESSION['username'], $team_id);
$result = mysqli_stmt_execute($stmt);
if ($result === false) {
$errors[] = 'Error: Could not add user to team. ' . mysqli_error($conn);
} else {
header('Location: team.php?id=' . $team_id);
exit;
}
}
}
}
All help is appreciated!