kavish M
kavish M

Reputation: 102

am getting this error, can any one help? "Column count doesn't match value count at row 1"

what i am trying to do is registering a new student to my database, hence storing it to the table student. my php code, i dont know where is the error, though am not a pro in php language. here is all my php codes. getting this error while trying to add records.

public function form(){
    $html = new Html();

    $html->div("row");
    $html->alert("message","Add New Student");

    $html->form("processstudent.php");

    $html->table("table table-bordered", "width:500px; margin:0 auto;");

    $html->input("", "hidden", "studentid", "");

    $html->row();
    $html->column(); echo "Firstname"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "firstname", null); $html->closecolumn();
    $html->closerow();

    $html->row();
    $html->column(); echo "Lastname"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "lastname", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Emailaddress"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "emailaddress", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Password"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "password", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Dateofbirth"; $html->closecolumn();
    $html->column(); $html->input("form-control", "date", "dateofbirth", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Contact Number"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "contactnumber", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Address"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "address", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Gender"; $html->closecolumn();
    $html->column(); $html->input("form-control", "text", "gender", null); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Program"; $html->closecolumn();
    $html->column(); $html->selectprogram(); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Cohort"; $html->closecolumn();
    $html->column(); $html->selectcohort(); $html->closecolumn();
    $html->closerow();


    $html->row();
    $html->column(); echo "Department"; $html->closecolumn();
    $html->column(); $html->selectdepartment(); $html->closecolumn();
    $html->closerow();


    $html->row();

    $html->column(); $html->closecolumn(); $html->column(); $html->input("btn btn-primary", "submit", "addstudent", "Add"); $html->closecolumn();
    $html->closerow();

    $html->closetable();

    $html->closeform();
    $html->closediv();
}


///////// Add Student 

public function add(){
    $mysql = new Mysql();
    $query = "insert into student VALUES ('','$this->firstname','$this->lastname','$this->emailaddress','$this->password','$this->dateofbirth','$this->contactnumber','$this->address','$this->gender','$this->cohort','$this->program','$this->department'); ";

    $mysql->execute($query);
    if($mysql->result)
        $mysql->successMessage ("Successfully inserted data");
}





}



?>

Upvotes: 1

Views: 66

Answers (1)

WheatBeak
WheatBeak

Reputation: 1031

It means you're trying to insert an incorrect number of values in relation to the number of columns in the database.

It's better for readability to do it like this:

INSERT INTO table (column1, column2, column3) VALUES ($value1,$value2,$value3)

then you'll know your columns and values match properly.

Upvotes: 3

Related Questions