php - Marksheet program: addition in codeignitor -


i trying make marksheet in php, mysql using codeignitor. have used xampp , created database.to store each record.the data being retrieved database, new record inserted edited

but problem in retrieving sum. not giving me sum answer means total marks. pasting code here, please me or correct me if wrong, new codeignitor.

i have tried function array_sum(), not giving me answer. , not giving me error code or query. either query sum in marksheet wrong or answer can't fetched view.

model/marksheet.php file

function tm() {   $data = array(               'math' => $_post['math'],               'eng' => $_post['eng'],               'bio' => $_post['bio'],               'total_marks' => $_post['total_marks']);               $this->db->insert('marks', $data);    // $mark = array_sum($data);    $mark= $_post['math'] + $_post['eng'] + $_post['bio'];   return $mark; } 

controller/welcome.php file

public function sum() {    $data['page_title'] = "new report";    $data['msg']="";     if(isset($_post['saveit'])) {      $this->marksheet->tm();        //$data['marks_obt'] = $this->marksheet->$mark;      $data['msg']="report added";    }     $this->load->view('header',$data);    $this->load->view('welcome_create', $data); } 

view/welcome_create.php file

i want total marks in text box.

<table>   <tr>     <td>mo</td>     <td><input type="text"  value="<?php if    (isset($mark)) echo $mark ?>"/>    </td>   </tr>   <tr>     <td><input type="submit" name="saveit" id="saveit" value="save"/></td>     <td><input type="button" name="cancel" id="cancel" value="cancel"/></td>   </tr> </table> 

  1. you need use $this->input->post('math'); instead of $_post['math']
  2. var_dump() incoming values if string need convert them integer . can not add these values like: "4" (string) + 5 (integer)
  3. if incoming data string need convert them integer.

    $math = "23"; $math = intval($math);


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -