2016-02-04 23 views
1

我想要做的是註冊一個新學生到我的數據庫,因此將其存儲到表學生。 我的PHP代碼,我不知道錯誤在哪裏,雖然我不是一個在PHP語言親。這裏是我所有的PHP代碼。 嘗試添加記錄時出現此錯誤。我得到這個錯誤,任何人都可以幫忙嗎? 「列數不匹配第1行的值計數」

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"); 
} 





} 



?> 
+1

這意味着您試圖插入到特定數量的列中,並且插入值的數量與表格的列數不匹配。 *計數*表格中的列數,然後*計數*您嘗試插入的項目數量。確保這些計數*匹配*。 –

+2

@ won-jun-bae在標題 – devpro

回答

3

這意味着你試圖插入與數據庫中的列數相關的錯誤數量的值。

這對可讀性更好地做到這樣的:

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

,那麼你就知道你的列和值正確地匹配。

+0

中提到的錯誤謝謝,它成功了(Y) –

相關問題