hi, all i am new in php developing

i need to know how i could make a user data hidden or inactive to the viewer of my website

without deleting this user data from my database


can i do that using php code?

if yes what is this coding criteria

thanks in advance

Recommended Answers

All 8 Replies

Member Avatar for deleted1234

You can add another field on your users table named 'activity' where you can flag a user as 'active' or 'inactive.' That way whenever you query the database you just have to "SELECT * FROM users WHERE activity = 'active'" so that it won't show your inactive users.

Member Avatar for diafol

More info please. As mentioned by Shinehah, a flag field like "activity" set to 0 or 1 (default) would work for most cases, but not knowing the actual use case, it's difficult to say.

here is my code

mysql_connect("localhost","root","");
         mysql_select_db("dbname");
       if($_REQUEST['select'] == "Activate")

      {
      mysql_query("update table1 set status=1 where P_id in $Patient_id");

}
if($_REQUEST['select'] == "Deactivate")

      {
      mysql_query("update table1 set status=0 where P_id in $Patient_id");

}

      $query = "SELECT * FROM `table1`";

      $dd=mysql_query($query);
 ?>

is this true?

Assuming the status column is the active flag you need, just change the last query to be:

SELECT * FROM TABLE1 WHERE status = 1
Member Avatar for diafol

Urghh. $_REQUEST!

mysql_connect("localhost","root","");
mysql_select_db("dbname");

if($_POST['select'] == "Activate"){
  mysql_query("UPDATE table1 SET status=1 WHERE P_id = $Patient_id");
}
if($_POST['select'] == "Deactivate"){
  mysql_query("UPDATE table1 SET status=0 WHERE P_id = $Patient_id");
}

$query = "SELECT * FROM table1";
$dd=mysql_query($query);

Can't see anything wrong with the above now. As long as $Patient_id is an integer. Also ensure that when you set the variable, it had the same case, i.e. $Patient_id and not $patient_id - they are treated as 2 different variables in php.

You can test to see if an update query has been completed successfully:

if($_POST['select'] == "Activate"){
  mysql_query("UPDATE table1 SET status=1 WHERE P_id = $Patient_id");
  echo "UPDATE table1 SET status=1 WHERE P_id = $Patient_id"; //check query
}
if($_POST['select'] == "Deactivate"){
  mysql_query("UPDATE table1 SET status=0 WHERE P_id = $Patient_id");
  echo "UPDATE table1 SET status=0 WHERE P_id = $Patient_id"; //check query
}

if(mysql_affected_rows()>0){
  echo "table updated";
}else{
  echo "table not updated";
}

Purely for testing.

i am unable to understand that how we will store the status (1 or 0) in our database?what should be the type of the status in the database?

Member Avatar for diafol

maybe tinyint, set to 1 digit, default = 0 or 1 if you want

What do you mean by activate and deactivate on php mysql?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.