title: Moodle Error writing to database
body: <p>I am getting Error writing to database in moodle:</p>
  
  <p>Code:</p>
  
  <pre><code>if (is_siteadmin()) {
  class addschedule_form extends moodleform {
  function definition () {
    $mform =&amp; $this-&gt;_form;
    $mform-&gt;addElement('text', 'id', 'Enter ID:');
    $mform-&gt;setType('id', PARAM_TEXT);
    $this-&gt;add_action_buttons(true, 'submit');
     }
     }
  
    $ti_form = new addschedule_form();
    $ti_form-&gt;get_data(); 
    if ($ti_form-&gt;is_cancelled()) {redirect('index.php');}
    if ($recs = $ti_form-&gt;get_data()) {
    $deleteit = $DB -&gt; delete_records('DELETE * FROM `mdl_schedules` WHERE id = ' . $recs -&gt; id . '');
    redirect('schedule.php');
     }
     }
  else {  }
  $ti_form-&gt;display();
  </code></pre>
  
  <p>What could be the reason? Any reference or help will be much appreciated.</p>
  
  <p>Regards</p>