I'm trying to update a column using PHP and MySQL.
Basically I have a database of adults and a database of children. When I child is added I want to add the ID(s) of the children to their respective adults.
When I child is added I grab the ID for that INSERT (I already have the ID of the adult).
If no children exist for the adult I simply add the ID of the child (this is always the case for the first run). The issue I have is when I add a second child for the same adult. The "Kids" column for the adult just doesn't update. I'm splitting the child ID's with a #.
It works perfectly the first time but just fails to update the table every other time.
The code I have is:
$sqlstatment = "INSERT INTO attendees (first, last, dob, access) VALUES ('$first','$last','$dob','$parent')"; $result = $link->query( $sqlstatment ); if ( $result ) { $kid_id = $link->insert_id; if ( $profile[ 'kids' ] === "" ) { $kids = $kid_id; } else { $kids = $profile[ 'kids' ]. "#" . $kid_id; } $updatesql = "UPDATE access SET kids = $kids WHERE id = $parent"; $updaccess = $link->query( $updatesql ); if ( $updaccess ) { outputToConsole("Adult update success"); } else { outputToConsole("Adult update failed"); } } Table format
