while update a form i got this error. can anyone help me?

while update a form i got this error. can anyone help me?

by ramya dhanesh -
Number of replies: 5

Coding error detected, it must be fixed by a programmer: moodle_database::update_record_raw() id field must be specified.

More information about this error

Debug info: 
Error code: codingerror
Stack trace:
  • line 1376 of \lib\dml\mysqli_native_moodle_database.php: coding_exception thrown
  • line 1432 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
  • line 75 of \local\candidates\edit_interview.php: call to mysqli_native_moodle_database->update_record()

showing the above error while updating the form. please advice.


Average of ratings: -
In reply to ramya dhanesh

Re: while update a form i got this error. can anyone help me?

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

According to that error message, line 75 of edit_interview.php is calling update_record(), and passing in an object with no "id" property.  It needs the "id" property to know which record to update.

In reply to Mark Johnson

Re: while update a form i got this error. can anyone help me?

by ramya dhanesh -

require("../../config.php");

require_once('edit_interview_form.php');

$id = optional_param('interview_id', 0, PARAM_INT);

if ($id) {

$candidates = $DB->get_record('locfb_interview', array('interview_id' => $id), '*', MUST_EXIST);

$pagedesc = 'Edit Interviews';

$pageparams = array('interview_id' => $id);


}else{

$candidates = new stdClass;

$pagedesc = 'Add Interviews';

$pageparams = array();

$candidates->interview_id = null;

}


$site = get_site();

$fullname = $site->fullname;

$systemcontext = context_system::instance();

//$PAGE->set_heading($fullname);

$PAGE->set_pagelayout('admin');

$PAGE->set_context($systemcontext);

$PAGE->set_url('/local/candidates/edit_interview.php', $pageparams);


$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=> 2, 'maxbytes'=> $CFG->maxbytes, 'context' => $systemcontext);


$args = array(

        'editoroptions' => $textfieldoptions

    );

$editform = new candidates_edit_interview_form(null, $args);

 

$editform->set_data($candidates);


if ($editform->is_cancelled()) {

redirect($CFG->wwwroot.'/local/candidates/interview.php');

}else if ($cnddata = $editform->get_data()) {

//echo "Data Fetch";

$candidates->interview_heading = $cnddata->interview_heading;

$candidates->content = $cnddata->content['text'];

$candidates->contact = $cnddata->contact;

$candidates->priority = $cnddata->priority;

$candidates->status = $cnddata->status;

$url = $CFG->wwwroot.'/local/candidates/interview.php';

    if (empty($candidates->interview_id)) {

        $candidate_id = $DB->insert_record('locfb_interview', $candidates);

$candidates->interview_id = $candidate_id;

print_r($candidates);

//exit;

$msg = 'interview added successfully.';

    } else {

$candidate_id = $candidates->interview_id;

        $DB->update_record('locfb_interview', $candidates);

$msg = 'Candidates updated successfully.';

    }

    redirect($url, $msg);

}


echo $OUTPUT->header();

echo $OUTPUT->heading($pagedesc);


$editform->display();


echo $OUTPUT->footer();


please show me where i made mistake.

In reply to ramya dhanesh

Re: while update a form i got this error. can anyone help me?

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi ramya,
I've already described the location and nature of the mistake in a fair amount of detail.  What more information do you need?
In reply to Mark Johnson

Re: while update a form i got this error. can anyone help me?

by ramya dhanesh -

Hello Mark,

for eg: when i echo the $candidate_id, it shows the id value as '17' . but the error shows that id value needed to specify.

$candidate_id = $candidates->interview_id;

$DB->update_record('locfb_interview', $candidates);


In reply to ramya dhanesh

Re: while update a form i got this error. can anyone help me?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The error message states that the record you are attempting to update has no 'id' field specified - you can have a 'candidate_id' field as well, if you want, but there must always be a field called 'id' (which must always be an auto-incrementing integer and the primary key for the table).

Assuming you use the XMLDB editor to write your DB install/upgrade code (which you always should do), this will be added for you.