I'm trying to add some data to a custom-db-table like this:
$sql ="insert into ext_user_data (userdata_id,vorname,nachname) values('$id','$vorname','$nachname')";
$stmt = $modx->prepare($sql);
$stmt->execute();
This works fine, expect by using this code I'm getting a new row in the table ext_user_data. I want to add this data to an existing row like this:
$sql ="insert into ext_user_data where id='136'(userdata_id,vorname,nachname) values('$id','$vorname','$nachname')";
$stmt = $modx->prepare($sql);
$stmt->execute();
But by using this code nothing gets added to the db-table.
So how can I add something to this custom-db-table to a given primary key? The primary key is the same as the $id.
To update data to an existing row you use a different SQL command, your code should look like this:
$sql ="update ext_user_data set `vorname` = '$vorname', `nachname` = '$nachname' where id='$id'";
$stmt = $modx->prepare($sql);
$stmt->execute();