You are attempting to:
Insert album data into an albums table (with foreign key to users).
Insert related songs into the albumsongs table, referencing:
The correct albumid (from the album just inserted).
The correct userid (from the session or current context).
However, the current logic has two main issues:
Issues in the Code:
You're calling it before any insertion into the albums table ($id = mysqli_insert_id($conn);), so it returns 0 or an unrelated ID.
You're using that value to:
Query the user table (incorrectly).
Associate the user/album/song IDs, leading to foreign key mismatches.
You should ideally store the logged-in user’s ID in a $_SESSION['userid'] or a securely passed POST/GET parameter.
lbumsongs table has columns: songid, userid, albumid, songname, songpath
You are referencing songaname1 and audio1 which are PHP variable names — not table column names. Use songname and songpath.