3

I am getting Error writing to database in moodle:

Code:

if (is_siteadmin()) {
class addschedule_form extends moodleform {
function definition () {
  $mform =& $this->_form;
  $mform->addElement('text', 'id', 'Enter ID:');
  $mform->setType('id', PARAM_TEXT);
  $this->add_action_buttons(true, 'submit');
   }
   }

  $ti_form = new addschedule_form();
  $ti_form->get_data(); 
  if ($ti_form->is_cancelled()) {redirect('index.php');}
  if ($recs = $ti_form->get_data()) {
  $deleteit = $DB -> delete_records('DELETE * FROM `mdl_schedules` WHERE id = ' . $recs -> id . '');
  redirect('schedule.php');
   }
   }
else {  }
$ti_form->display();

What could be the reason? Any reference or help will be much appreciated.

Regards

MOZ
  • 768
  • 4
  • 19
  • 33

1 Answers1

2

The syntax is

$DB->delete_records('schedules', array('id' => $recs->id));

You might want to keep this open in a tab for reference - https://docs.moodle.org/dev/Data_manipulation_API

Russell England
  • 9,436
  • 1
  • 27
  • 41