Answer the question
In order to leave comments, you need to log in
How to update a record by ID in a form?
There is a form that adds a record.
We have an id field. pk to db.
It is necessary that if a key is entered in the field that already exists, then the data is updated, if not, then a new pk is added, respectively
if (isset($_POST[get_class($model)]))
{
$model->attributes = $_POST[get_class($model)];
if ($model->validate())
{
$event = new Calendar();
$event->id = $model->id;
$event->id_name = $model->id_name;
$event->address = $model->address;
$event->date = $model->date;
$event->company = $model->company;
$event->timestart = $model->timestart;
$event->timeend = $model->timeend;
$event->other_info = $model->other_info;
$event->save();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question