79713116

Date: 2025-07-24 09:44:32
Score: 0.5
Natty:
Report link

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:

  1. Misuse of mysqli_insert_id() mysqli_insert_id($conn) returns the last inserted auto-increment ID from the same connection, after an INSERT.

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.

  1. Missing User Context There's no mention of how the userid is being passed or retained.

You should ideally store the logged-in user’s ID in a $_SESSION['userid'] or a securely passed POST/GET parameter.

  1. Incorrect Column Names in Second Insert

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.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Devashish Mishra