Create a relationship between the data base and form

Create a relationship between the data base and form

by hadile zahra -
Number of replies: 0

salam

help me please

I want to record note in the database and display note in the following table ,

But the note subject to the identity of subject i'm write code of this problem

but does not work , this code not take the value of sujetid

I'm write three files :

1/note_form.php

<?php

require_once(dirname(dirname(dirname(__FILE__))).'/config.php');

require_once($CFG->libdir.'/formslib.php');

class note_form extends moodleform {

    public function definition() {

$Longueur = 120;

        $mform = $this->_form;

$rule='required';$entete='Note';

$mform->addElement('header', 'nameforyourheaderelement', $entete);

        $annees = array(1=>'1',2=>'2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20');

$select = $mform->addElement('select', 'note', 'note', $annees);

        $mform->setDefault('titre',$this->_customdata['n1']);

            if($this->_customdata['buttons'])

{

$this->add_action_buttons();

}


$mform->addElement('hidden', 'id');

        $mform->setType('id', PARAM_INT);

$mform->addElement('hidden', 'viewall');

        $mform->setType('viewall', PARAM_INT);

    }

}

2/soumettre_note.php

<?php


require_once(dirname(dirname(dirname(__FILE__))).'/config.php');

require_once(dirname(__FILE__).'/note_form.php');


$id = required_param('id', PARAM_INT);

$sujetid = required_param('sujetid', PARAM_INT);

$viewall = required_param('viewall', PARAM_INT);


$n1 = optional_param('n1', '', PARAM_TEXT);

//$p2 = optional_param('p2', '', PARAM_TEXT);



if ($id) {

    $cm         = get_coursemodule_from_id('encadrement', $id, 0, false, MUST_EXIST);

    $course     = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

    $encadrement  = $DB->get_record('encadrement', array('id' => $cm->instance), '*', MUST_EXIST);

} elseif ($e) {

    $encadrement  = $DB->get_record('encadrement', array('id' => $e), '*', MUST_EXIST);

    $course     = $DB->get_record('course', array('id' => $encadrement->course), '*', MUST_EXIST);

    $cm         = get_coursemodule_from_instance('encadrement', $encadrement->id, $course->id, false, MUST_EXIST);

} else {

    error('You must specify a course_module ID or an instance ID');

}


require_login($course, true, $cm);

$context = context_module::instance($cm->id);


add_to_log($course->id, 'encadrement', 'view', "view.php?id={$cm->id}", $encadrement->name, $cm->id);


/// Print the page header


$PAGE->set_url('/mod/encadrement/view.php', array('id' => $cm->id));

$PAGE->set_title(format_string($encadrement->name));

$PAGE->set_heading(format_string($course->fullname));

$PAGE->set_context($context);


echo $OUTPUT->header();

?>

<?php



$inf = new stdClass();

$inf->id = $id;

$inf->viewall = $viewall;

$inf->sujetid = $sujetid;


$s_form = new note_form(null, array('buttons'=>1,'n1'=>$n1));


$s_form->set_data($inf);


if ($s_form->is_cancelled())

{

redirect('view.php?id='.$id.'&viewall='.$viewall);

} elseif ($s_data=$s_form->get_data())

{

redirect('confirmer_note.php?id='.$id.'&viewall='.$viewall.'&sujetid='.$sujetid.'&n1='.$s_data->note);

}

?>

<?php

$s_form->display();

echo $OUTPUT->footer();

3/confirmer_note.php

<?php


require_once(dirname(dirname(dirname(__FILE__))).'/config.php');


$id = required_param('id', PARAM_INT);

$sujetid =required_param('sujetid', PARAM_INT);

$viewall = required_param('viewall', PARAM_INT);


$n1 = required_param('n1', PARAM_TEXT);



if ($id) {

    $cm         = get_coursemodule_from_id('encadrement', $id, 0, false, MUST_EXIST);

    $course     = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

    $encadrement  = $DB->get_record('encadrement', array('id' => $cm->instance), '*', MUST_EXIST);

} elseif ($e) {

    $encadrement  = $DB->get_record('encadrement', array('id' => $e), '*', MUST_EXIST);

    $course     = $DB->get_record('course', array('id' => $encadrement->course), '*', MUST_EXIST);

    $cm         = get_coursemodule_from_instance('encadrement', $encadrement->id, $course->id, false, MUST_EXIST);

} else {

    error('You must specify a course_module ID or an instance ID');

}


require_login($course, true, $cm);

$context = context_module::instance($cm->id);


add_to_log($course->id, 'encadrement', 'view', "view.php?id={$cm->id}", $encadrement->name, $cm->id);


/// Print the page header


$PAGE->set_url('/mod/encadrement/view.php', array('id' => $cm->id));

$PAGE->set_title(format_string($encadrement->name));

$PAGE->set_heading(format_string($course->fullname));

$PAGE->set_context($context);


echo $OUTPUT->header();

?>

<?php

$inf = new stdClass();

$inf->instanceid = $id;

$inf->id = $sujetid;

$inf->userid = $USER->id;

$inf->anneescolaire = $encadrement->anneescolaire;

$inf->n1 = $n1;





if ($s_data=data_submitted() && confirm_sesskey()) {


$db = new PDO( 'mysql:host=localhost;dbname=moodle', $CFG->dbuser, $CFG->dbpass);

$insert_1 = $db->prepare('UPDATE mdl_sujet_pfe SET noteencadreur=:? WHERE id=:?');

    $insert_1->bindParam(':?', $n1, PDO::PARAM_INT);

    $insert_1->bindParam(':?', $sujetid, PDO::PARAM_INT);

    $insert_1->execute();

    //$insert_1->execute(array( $inf->n1));



$message = 'merci pour votre collaboration, cher '.$USER->firstname.'    '.$USER->lastname;


redirect('continuer.php?id='.$id.'&message='.$message);

}

else{


$optionsyes = array('id'=>$id,'viewall'=>$viewall,

'n1'=>$inf->n1,

'sesskey'=>sesskey());


$optionsno  = array('id'=>$id, 'viewall'=>$viewall,

'n1'=>$inf->n1,


    );


echo $OUTPUT->confirm('êtes-vous sûres de vouloir soumettre votre note?', new moodle_url('confirmer_note.php',$optionsyes), new moodle_url('soumettre_note.php',$optionsno));


}

?>

<?php

echo $OUTPUT->footer();

the problem in sujetid this variable is not registered .($sujetid =required_param('sujetid', PARAM_INT);)

Attachment 5.jpg
Attachment 7.jpg
Average of ratings: -