Jump to content

Delete Users From Database


AndrewJ1313

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/95553-delete-users-from-database/
Share on other sites

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 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

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

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

}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.