So I have a sql statement in a php file that is related to a form that gets input from a user. When they enter in a genre though it updates all the records in that column and not the specific one they chose.
The original statement I had that works is this first code but it edits the whole column. So I have been trying out other clauses so it only changes the one with the matching album_id but have not had any luck. Sample Table data
$sql = "UPDATE album
SET genre_id = (SELECT genre_id
FROM genre
WHERE genreName='" . $_POST['lstGenre'] . "'
)";
Above is what I started with and keep going back to. Result from code above changes genre in entire column
$sql = "UPDATE album
SET genre_id = (SELECT genre_id
FROM genre
WHERE genreName='" . $_POST['lstGenre'] . "'
)
FROM album
WHERE album_id='" . $_POST['album_id'] . "'";
That is one version I tried but then it does not update anything. This is what I am looking for: Different genre for each case
This works I solved it:
$sql = "UPDATE album
SET genre_id = (SELECT genre_id
FROM genre
WHERE genreName='" . $_POST['lstGenre'] . "'
)
FROM album
WHERE album_id='" . $thisAlbum['album_id'] . "'";