0

Sorry for my shaky english.

My page automatically computes a user's age based on their birthday using js then outputs the age on an <input> field so my PHP can pick it up and insert into database

issue is the value PHP is getting from the <input> is null.

Error (Age is what's causing the error, it's NULL):

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0) VALUES ('32644173', 'Diego', 'Diego', 'G', 'Transferee', 'Male', '10/26/1999'' at line 1

INSERT INTO `tblstudents` (`stud_id`, `s_first`, `s_last`, `s_mi`, `s_stat`, `s_gender`, `s_bday`, `s_age`, `s_eth`, `s_rel`, `s_marstat`, `s_nspouse`, `s_nchild`, `s_brgy`, `s_muni`, `s_provi`, `s_nor`, `s_guardn`, `s_guardno`, `s_guardadd`, `s_guardrel`, 0)
VALUES ('32644173', 'Diego', 'Diego', 'G', 'Transferee', 'Male', '10/26/1999', NULL, 'Ifugao', 'Hindu', 'Single', '', '', 'Graceville', 'Solano', 'Bulacan', 'Boarding House', '', '', '', '', 's_datecreated')

Html:

<input name="s_age" disabled id="age" class="appearance-none w-full py-2.5 px-4 text-coolGray-900 text-base font-normal bg-white border outline-none border-coolGray-200 focus:border-green-500 rounded-lg shadow-input">

JS File:

function ageCalculator() {
    var userinput = document.getElementById("DOB").value;
    var dob = new Date(userinput);
    var month_diff = Date.now() - dob.getTime();
    var age_dt = new Date(month_diff);
    var year = age_dt.getUTCFullYear();
    var age = Math.abs(year - 1970);
    return document.getElementById("age").value = age;
}

PHP (Please ignore the comments and the get/set methods):

public function insert_students() //INSERT
    { //Update to audit staff       
        $data = array(                              //Table DRAFT
            'stud_id' => $this->getSID(),           //int(11) NN
            's_first' => $this->getSFName(),        //varchar(50) NN, NULL
            's_last' => $this->getSLName(),         //varchar(50) NN, NULL
            's_mi' => $this->getSMI(),              //varchar(25) NN, NULL
            's_stat' => $this->getSStat(),          //varchar(25) NN, NULL
            's_gender' => $this->getSGender(),      //varchar(25) NN, NULL
            's_bday' => $this->getSBDay(),          //varchar(25) NN, NULL
            's_age' => $this->getSAge(),            //int(5) NN, NULL
            's_eth' => $this->getSEth(),            //varchar(25) NN, NULL
            's_rel' => $this->getSRel(),            //varchar(25) NN, NULL
            's_marstat' => $this->getSmarstat(),    //varchar(45) NN, NULL
            's_nspouse' => $this->getSNSpouse(),    //varchar(80) NULL
            's_nchild' => $this->getSNChild(),      //int(2) NULL
            's_brgy' => $this->getSBrgy(),          //varchar(45) NN, NULL
            's_muni' => $this->getSMuni(),          //varchar(45) NN, NULL
            's_provi' => $this->getSProvi(),        //varchar(45) NN, NULL
            's_nor' => $this->getSNOR(),            //varchar(45) NN, NULL
            's_guardn' => $this->getSGuardn(),      //varchar(80), NULL
            's_guardno' => $this->getSGuardno(),    //int(11), NULL
            's_guardadd' => $this->getSGuardadd(),   //varchar(200), NULL
            's_guardrel' => $this->getSGuardrel(),  //varchar(20), NULL
            's_datecreated',                        //TIMESTAMP, CURRENT_TIMESTAMP
        );
        $query = $this->db->insert('tblstudents', $data);
    }

Many thanks in advance and thank you for taking the time to read my issue!

nullblank
  • 1
  • 1
  • Elements with the disabled attribute are not submitted or you can say their values are not posted https://stackoverflow.com/a/7357314/14527588 – Mai Truong Oct 19 '22 at 04:12

0 Answers0