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

Link to comment
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

 

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

Link to comment
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 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

Link to comment
Share on other sites

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

}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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