I just joined the group. And I am going through the learning curve of Php.
Hope someone could help me out here.
I want to have a form that consist of 5 text inputs, and 4 buttons(referred by $action [0-3] ).
What I am trying to do is, after the user click the first button to set the user's rights, it will update or insert into database for the specific resource that the user has the permission to.
but i was checking the user_id and res_id only initially, but can i add another checking which is not to pass the user if they missed fields like:
resource_type and permission are blank, while there is no existing record in the db (flag of $rExist).
Code: Select all
function SetUserRights($user_id,$res_type,$res_id,$permission,$action){
if($action == '0' && (!empty($user_id)) && (!empty($res_id))) {
$rExist = FALSE;
$sql = "SELECT * FROM Resource WHERE user_id='$user_id' AND res_id='$res_id'";
$rsUserRights = $this->dbConn->Execute($sql);
if ($rsUserRights->RowCount() > 0) {
$rExist = TRUE;
$sqlUpdate = "UPDATE Resource SET permission='$permission' WHERE user_id='$user_id' AND res_type='$res_type' AND res_id='$res_id'";
$this->dbConn->Execute($sqlUpdate);
echo "The specified user_id permission has been updated!";
}else {
$sqlInsert = "INSERT INTO Resource (user_id, res_type, res_id, permission)";
$sqlInsert .= "VALUES('$user_id', '$res_type', '$res_id', '$permission')";
$this->dbConn->Execute($sqlInsert);
echo "The permission has been added for the specified user!";
// Here is what I am trying to do:
if ($rExist = FALSE && (($user_id == '')||($res_type == '')||($permission == ''))){
echo "There was not enough information given to update neither to insert into the database!";
}
}
} else {
echo "either user_id or/and res_id input is missing!";
}
}