0

Hello everyone I'm new here and right now I'm making a website for a project I got a last problem I need to fix one of the forms which is not submitting the data to the database and it's not redirecting the user to the previous page

I tried to compare the code of the form with other forms in my controller, and my views and my model but I can't see any differences . I checked several times for hours and I tried to search some solutions but none of them work

First this is the controller function that takes the data from the form in order to make and update in the database

public function modifier_stage($stage_id) { $this->load->helper(array('form','url')); $this->load->model('mStages'); $stage = $this->mStages->get_non_valide($stage_id); if(!$stage) redirect('main_stage/afficher_gestion_stages'); $data = array(); $data['stage'] = $stage; $this->load->library('form_validation'); $this->form_validation->set_rules('intitule', 'Intitule_stage','required'); $this->form_validation->set_rules('nom_entreprise','Nom entreprise','required'); $this->form_validation->set_rules('date_debut','Date de début','required'); $this->form_validation->set_rules('date_fin','Date de fin','required'); $this->form_validation->set_rules('adresse','Adresse','required'); $this->form_validation->set_rules('mission','Mission du stage','required'); $this->form_validation->set_rules('code_postal','code postal','required'); $this->form_validation->set_rules('ville','Ville','required'); $this->form_validation->set_rules('pays_stage','Pays','required'); $this->form_validation->set_rules('mail','Mail auteur','required'); if($this->form_validation->run() == FALSE) { $this->load->view('stage_modif',$data); echo validation_errors(); } else{ $emailauteur = $this->input->post('mail'); $entreprise_nom = $this->input->post('nom_entreprise'); $idauteur = $this->mStages->get_utilisateur_id($emailauteur); $entreprise_id = $this->mStages->get_entreprise_id($entreprise_nom); $stage_modif = array( 'intitule_stage' => $this->input->post('intitule'), 'entreprise' => $entreprise_id, 'date_debut_stage' => $this->input->post('date_debut'), 'date_fin_stage' => $this->input->post('date_fin'), 'adresse' => $this->input->post('adresse'), 'mission' => $this->input->post('mission'), 'code_postal' => $this->input->post('code_postal'), 'ville' => $this->input->post('ville'), 'pays' => $this->input->post('pays_stage'), 'auteur' => $idauteur, ); $this->mStages->update_stage($stage_id,$stage_modif); redirect('main_stage/afficher_gestion_stages'); } } 

And now this is the model function that makes the update in the database

 public function update_stage($stage_id,$data) { $this->db->where('id_stage',$stage_id); $query = $this->db->update('stage', $data); } 

Finally this is the code of the form in the view

 <form method="POST" > <label> Intitulé du Stage </label><input class="pseudo" id="pseudo" type="text" name="intitule" value="<?php echo set_value('intitule',$stage->intitule_stage);?>" required="" > <br> <label> Nom Entreprise </label><input class="pseudo" id="pseudo" type="text" name="nom_entreprise" value="<?php echo set_value('nom_entreprise',$stage->nom_entreprise);?>" required=""> <br> <br> <label> Date de début </label><input type="date" name="date_debut" class="pseudo" id="pseudo" value="<?php echo set_value('date_debut',$stage->date_debut_stage);?>" required="" > <br> <br> <label> Date de fin </label><input type="date" name="date_fin" class="pseudo" id="pseudo" value="<?php echo set_value('date_fin',$stage->date_fin_stage);?>" required=""> <br> <br> <label> Adresse du stage</label><input class="pseudo" id="pseudo" type="text" name="adresse" value="<?php echo set_value('adresse',$stage->stage_adresse);?>" required=""> <br> <br> <label> Mission du stage</label><input class="pseudo" id="pseudo" type="text" name="mission" value="<?php echo set_value('mission',$stage->mission);?>" required=""> <br> <br> <label> Code Postal du stage </label><input class="pseudo" id="pseudo" type="text" name="code_postal" value="<?php echo set_value('code_postal',$stage->cp_stage);?>" required=""> <br> <br> <label> Ville du stage </label><input class="pseudo" id="pseudo" type="text" name="ville" value="<?php echo set_value('ville',$stage->ville_stage);?>" required=""> <br> <br> <label> Mail Auteur du stage </label><input class="pseudo" id="pseudo" type="mail" name="mail" value="<?php $this->load->model('mStages'); echo set_value('mail',$this->mStages->get_utilisateur_email($stage->auteur));?>" required="" > <br> <br> <label> Pays du stage </label><input class="pseudo" id="pseudo" type="text" name="pays_stage" value="<?php echo set_value('pays_stage',$stage->pays_stage);?>" required="" > <br> <br> <br> <br> <center><input type="submit" id="button" value="Modifier les valeurs"><?php echo anchor("/main_stage/afficher_confirmation_suppression_stage/$stage->id_stage",'Supprimer', 'class="btn_choice" ' ); ?></center> <br> <br> </div> </form> 

I don't know what is wrong with my code even after comparing it with other forms that work without problem. I need to see why when I click on the submit button I'm stuck on the form page instead of being redirected to the previous page and having the data updated in the database.

1 Answer 1

1

Change

<form method="POST"> 

to

<form method="POST" action="[url of your php script]"> 

More about form's action tag here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer it works now and I noticed many mistakes i did in the code. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.