I am trying to develop a registration system (I am developing this site-> bottlesbeach.eu just to train my practical knowledge on the backend part) that inserts the username, email, password, session string and taken string randomly from the avatar array which will mean the name of user avatar image:
$avatars = array("avatar0.png", "avatar1.png", "avatar2.png", "avatar3.png", "avatar4.png");
$k = array_rand($avatars);
$v = $array[$k];
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$query = "INSERT INTO users SET username = ?, email = ?, avatar = ?, password = ?, sessionid = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('sssss', $username, $email, $v, $password, $randomString);
$stmt->execute();
$sub = true;
This is the error that is thrown when the form is submitted:
Column 'avatar' cannot be null
I don't know why I'm getting this error, maybe the '$ v' variable is null although I don't know why it should be.
Anyone know what caused this exception in my case? how can i solve?