0
我開始玩ajaxCRUD這似乎是簡單但有效的類。
我有一個表的用戶是這樣的:ajaxCRUD:關於插入的兩個問題
CREATE TABLE tbl_users (
usr_id INT NOT NULL AUTO_INCREMENT ,
usr_name VARCHAR(64) NOT NULL DEFAULT '' ,
usr_surname VARCHAR(64) NOT NULL DEFAULT '' ,
usr_pwd VARCHAR(64) NOT NULL ,
usr_level INT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (usr_id)
) ENGINE = InnoDB;
我的PHP代碼:
<?php
$tblUsers->omitPrimaryKey();
$tblUsers->displayAs("usr_name", "Nome");
$tblUsers->displayAs("usr_surname", "Cognome");
$tblUsers->displayAs("usr_pwd", "Password");
$tblUsers->displayAs("usr_level", "Livello");
$tblUsers->omitField("usr_pwd");
$tblUsers->modifyFieldWithClass("usr_pwd", "password");
$allowable_vals = array(1 => "USER", 2 => "ADMIN", 3 => "SUPERUSER");
$tblUsers->defineAllowableValues("usr_level", $allowable_vals);
$tblUsers->formatFieldWithFunction('usr_level', 'make_usr_level');
$tblUsers->onAddExecuteCallBackFunction("AddCallBack");
$tblUsers->addButtonToRow("Dettagli", "UserDetails.php");
$tblUsers->addButtonToRow("Collega case", "HousesList.php");
$tblUsers->setLimit(30);
#my self-defined functions used for formatFieldWithFunction
function make_usr_level($val){
return FAUser::LevelToString($val);
}
function AddCallBack($array)
{
//these indexes are the fields of the db
$success = qr("INSERT INTO tbl_users
(usr_id,
usr_name,
usr_surname,
usr_pwd,
usr_level)
VALUES (NULL,
'" . $array[usr_name] . "',
'" . $array[usr_surname] . "',
AES_ENCRYPT('" . $array[usr_pwd] . "',
SHA2('FonteAlma_2013', 512)),
" . $array[usr_level] . ");");
}
#actually show to the table
$tblUsers->showTable();
?>
表顯示正常,並顯示已插入的用戶,但是,當我添加一個新用戶,我得到:
4 - TheGivenName - TheGivenSurname - [BLOB - 7 B] - 0
所以密碼和用戶級別設置不好。另外,當我將表格中的級別字段編輯爲包含三個級別的組合框時,無論我選擇什麼值,我都會得到0。
我哪裏錯了?
問候。