Jump to content

NaderH

Members
  • Posts

    24
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

NaderH's Achievements

Member

Member (2/5)

0

Reputation

  1. I am afraid of corrupting my main project so I am working on another one for testing, Sorry I am still beginner.
  2. That's the main structure Array ( [id] => [name] => [username] => [password] => [user_level] => [image] => [status] => [last_login] => ) But this this the one I am working on ( for testing) Array ( [id] => [username] => [user_level] => )
  3. That's the users table structure id user_name user_level --------------------------------------- 1 Admin 1 2 Editor1 2 3 User1 3 4 Editor2 2 5 User2 3 6 User3 3
  4. yes the id of the user from the users table ( if you used it with the users ) function find_by_id($table,$id) { global $db; $id = (int)$id; if(tableExists($table)){ $sql = $db->query("SELECT * FROM {$db->escape($table)} WHERE id='{$db->escape($id)}' LIMIT 1"); if($result = $db->fetch_assoc($sql)) return $result; else return null; } }
  5. That's the echo code I used for all queries <p>Role changing query</p> <?php $update = "UPDATE blog.roles SET role_status = '0' WHERE id ='2'"; $uresult = $db->query($update) or die ($update."<br/><br/>".mysql_error()); if($uresult && $db->affected_rows() === 1) { echo ('Role status changed successfuly'); } else { echo ('Role status changing failed'); } ?> <br> <p>Users with role blocked selecting query</p> <?php $selectb = "SELECT users.username FROM blog.users JOIN blog.roles ON roles.id = users.user_level WHERE roles.role_status = '0'"; $sbresult = mysql_query($selectb) or die ($selectb."<br/><br/>".mysql_error()); while($sbrow = mysql_fetch_assoc($sbresult)) { echo $sbrow['username']; // Print a single column data echo print_r($sbrow); } // Print the entire row data ?> <br> <p>Users with role allowed selecting query</p> <?php $selecta = "SELECT users.username FROM blog.users JOIN blog.roles ON roles.id = users.user_level WHERE roles.role_status = '1'"; $saresult = mysql_query($selecta) or die ($selecta."<br/><br/>".mysql_error()); while($sarow = mysql_fetch_assoc($saresult)) { echo $sarow['username']; // Print a single column data echo print_r($sarow); } // Print the entire row data and that's the output Role changing query Role status changed successfuly Users with role blocked selecting query Editor@userArray ( [username] => Editor@user ) 1 Users with role allowed selecting query Admin@userArray ( [username] => Admin@user ) 1User@userArray ( [username] => User@user ) 1 Actually, I don't know.. aren't you believe that the queries are working or what!!
  6. Sorry for the quality of the video, it is Google Drive
  7. The full code is in the post ( the queries and the function. I don't have anything else for this task $db->escape() function is to remove special characters from the value before submitting it to the database public function escape($str){ return $this->con->real_escape_string($str); } function real_escape($str){ global $con; $escape = mysqli_real_escape_string($con,$str); return $escape; } and this is better than the echo https://drive.google.com/file/d/13NlsUQVqlfRbLWTyqsbONfrhMHTkcm-V/view?usp=sharing
  8. This to change the role status ( blocked or not ) $query = "UPDATE roles SET role_status = '{$role_status}' WHERE id='{$db->escape($roles['id'])}' LIMIT 1"; and this to get or call any user with a blocked role ( user_level is the user role and it = the role_id ) so I am getting them through their level which is = role_id which is = '0' or '1' .. I wrote that in the post above, you can checi it $sql = "SELECT users.id FROM users JOIN roles ON roles.id = users.user_level WHERE roles.role_status = '{$db->escape($role_status)}'"; and both of them are working well by testing them with phpmyadmin, but editors is still active so I know that the solution is with the right function which I can't write it correctly ( and of course I know that I can't use (role_status) directly )
  9. and that query is working fine also, but editors didn't get blocked
  10. yes that exactly what should happen, But I can't make it happen
  11. is there any way to block a group of users according to their role, I mean I want to block all editors instead of doing that one by one, status column in users table only block a user, but I want to block a group of users at once, the SQL query I wrote is already get the users with the blocked role, but I can't use that query without the function which will process what I need, if their any way to write a function that combines users and roles to get the users with the blocked roles and block them at once ?
  12. I don't know If I can suppose that this is helpful or not.
  13. I am not using it, I just put it here in that post to ask what should I write instead of it to complete the post, I could write my name to make it more clear , it was just an example, I am asking for help to complete the function ...
  14. I know that before ( there are not a column called like that in users table, I wrote it to ask what should I write instead of it, I needed help to complete the function.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.