Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #37 from noten-app/user-unique-ids
Browse files Browse the repository at this point in the history
πŸ› Fix class creation without an id
  • Loading branch information
CuzImBisonratte authored Nov 22, 2023
2 parents bdabd75 + e28f9a4 commit 884d2d7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions subjects/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
// Remove # from color
$subjectColor = str_replace("#", "", $subjectColor);

// Generate id (8char random string)
$subjectID = bin2hex(random_bytes(4));

// Add subject to DB and get inserted ID
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["subjects"] . ' (name, color, user_id, grade_k, grade_m, grade_t, grade_s, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('sssiisis', $subjectName, $subjectColor, $_SESSION["user_id"], $gradingTypeK, $gradingTypeM, $gradingTypeT, $gradingTypeS, $_SESSION["setting_years"]);
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["subjects"] . ' (id, name, color, user_id, grade_k, grade_m, grade_t, grade_s, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('ssssiisis', $subjectID, $subjectName, $subjectColor, $_SESSION["user_id"], $gradingTypeK, $gradingTypeM, $gradingTypeT, $gradingTypeS, $_SESSION["setting_years"]);
$stmt->execute();
$subjectID = $stmt->insert_id;
$stmt->close();
exit(json_encode(array("success" => true, "subjectID" => $subjectID)));
} else die("Error with the Database");
Expand Down

0 comments on commit 884d2d7

Please sign in to comment.