AndrewJ1313 Posted March 11, 2008 Share Posted March 11, 2008 There is probably a simple answer to this, but I can't figure it out. I have a website and database (php5 & MySQL 5.1). I have an admin section where I can create, update and modify users and their privileges, however, is there a way I can forbid access through the web site to delete a particular user? I.E. I have an Admin user that I don't want to accidentally delete, but there are other users that I may want to delete eventually. Can I protect an individual row in a database from deletion? Thanks, Andrew Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 add a `readonly` coloum to your database and mark your admin users '1' in that field. change your sql to <? $sql = "DELETE FROM `users` WHERE username='SomeUserName' AND `readonly`!= '1' "; ?> Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 i dont know why i put `` around "readonly" but you dont have to <? $sql = "DELETE FROM `users` WHERE username='SomeUserName' AND readonly != '1' "; ?> Can you understand what im explaining? other than that I dont think you can make a row readonly Quote Link to comment Share on other sites More sharing options...
cyrixware Posted March 11, 2008 Share Posted March 11, 2008 i dont know why i put `` around "readonly" but you dont have to <? $sql = "DELETE FROM `users` WHERE username='SomeUserName' AND readonly != '1' "; ?> Can you understand what im explaining? other than that I dont think you can make a row readonly Yep... You can create in your admin area a status to every user ex. enabled / disabled. And in your field named 'readonly' update every time if you want to enable or disable the user. Make sense? hehehehe Quote Link to comment Share on other sites More sharing options...
AndrewJ1313 Posted March 11, 2008 Author Share Posted March 11, 2008 i dont know why i put `` around "readonly" but you dont have to <? $sql = "DELETE FROM `users` WHERE username='SomeUserName' AND readonly != '1' "; ?> Can you understand what im explaining? other than that I dont think you can make a row readonly I think I get it. So the users I want to be able to delete, put a "1" in the "readonly" field and the users I don't want to delete put something different, but make the SQL code a "1" not a variable. Will the SQL automatically redirect me with an error that it cannot delete, or do I need to code that as well? Thank you, Andrew Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 nope. it simply wont delete it. its the same thing as if the user id wasent in the database. Quote Link to comment Share on other sites More sharing options...
AndrewJ1313 Posted March 11, 2008 Author Share Posted March 11, 2008 nope. it simply wont delete it. its the same thing as if the user id wasent in the database. Gotcha! Thank you very much! Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 although if you wanted an alert you can do something like this: <? $result = mysql_query("SELECT * FROM `users` WHERE username='SomeUserName'"); $row = mysql_fetch_array($result); if($row['readonly'] == '1'){ echo "Cannot delete this user!"; }else{ mysql_query("DELETE FROM `users` WHERE username='SomeUserName' AND `readonly`!= '1' "); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.