How to create activate deactivate and delete records in database using php

How to create activate deactivate and delete records in database using php:

active

—————————————————————–

Create page home.php:-

<?php
session_start();
$con=mysql_connect(“localhost”,”root”,””) or die(“mysql is not connected”);
$database=mysql_select_db(“myproject”,$con) or die(“database is not connected”);
if($_SESSION[‘username’]==” && $_SESSION[‘userpassword’]==”)
{
$_SESSION[‘msg’]=”Please enter login details”;
header(“Location:index.php”);
}
?>
<html>
<head>
<title>user home page</title>
<script>
function checkall(frm)
{
len = objForm.elements.length;
var i=0;
for( i=0 ; i<len ; i++){
if (frm.elements[i].type==’checkbox’)
frm.elements[i].checked=objForm.check_all.checked;
}
}
function del_prompt(frmobj,comb)
{
if(comb==’Delete’){
if(confirm (“Are you sure you want to delete record(s)”))
{
frmobj.action = “action.php?value=Delete”;
frmobj.submit();
}
else{
return false;
}
}
else if(comb==’Deactivate’){
frmobj.action = “action.php?value=Deactivate”;
frmobj.submit();
}
else if(comb==’Activate’){
frmobj.action = “action.php?value=Activate”;
frmobj.submit();
}
}

</script>

</head>

<body bgcolor=”#FFFFCC”>

<div style=”background-color:#006699; height:150px; width:100%; float:left; border:1px #000000 solid;”><div style=”float:right; margin-top:20px; margin-right:10px; color:#FFFFFF;”> Welcome USER <a href=”logout.php”>Logout</a></div></div>
<div style=”float:left; width:100%”>
<div style=”float:left; background-color:#00CCFF; width:24%; border:1px #000000 solid;”></div>
<div style=”background-color:#CCCCCC; height:50px; float:right; width:75%; border:1px #000000 solid;”>
<div style=”float:left; height:50px; width:100%;”>
<div style=”float:left; margin-top:20px; margin-left:10px;”>Manage User</div>
<div style=”float:right; margin-top:20px; margin-right:10px;”><a href=”addform.php” style=”text-decoration:none;”><input type=”button” name=”button” value=”add new” /></a></div>
</div>
</div>
<form name=”frm” action=”” method=”post”>
<div style=”float:right; background-color:#006666; width:75%; border:1px #000000 solid;”>
<div style=”float:left; height:50px; width:100%; padding-top:10px;”>
<div style=”float:left; margin-left:100px;”>Artist Name:<input type=”text” name=”artistname” value=”” /></div>
<div style=”float:left; margin-left:100px;”><input type=”submit” name=”search” value=”search” /></div>
<div style=”float:right; margin-right:10px;”>View All</div>

</div>
<?php
$query=”select * from artists”;
$result=mysql_query($query);
?>
<table width=”100%” border=”1″ bgcolor=”#FFCCCC”>
<tr  bgcolor=”#0099CC”><th>S.No</th>
<td>Artist Name</td>
<td>Adress</td>
<td>email</td>
<td>Phone</td>
<td>Image</td>
<td>Description</td>
<td>Status</td>
<td>Feture</td>
<td>Action</td>
<td></td>

</tr>
<?php
$i=1;
while($data=mysql_fetch_array($result))
{
//$id=$data[‘id’];
//$status=$data[‘status’];
?>
<tr  bgcolor=”#0099CC”>
<td><?php echo $i++; ?></td>
<td><?php echo $data[‘artistname’]; ?></td>
<td><?php echo $data[‘address’]; ?></td>
<td><?php echo $data[’email’]; ?></td>
<td><?php echo $data[‘phone’]; ?></td>
<td><img src=”<?php echo “img/”.$data[‘image_name’]; ?>” width=”88″ height=”96″/></td>
<td><?php echo $data[‘description’]; ?></td>
<td><?php echo $data[‘status’] ?></td>
<td></td>
<td><a href=”edit.php?id=<?php echo $data[‘id’] ?>”>Edit</a></td>

<td><input type=”checkbox” name=”checkbox[]” value=”<?php echo $data[‘id’]; ?>” /></td>
</tr>

<?php
}
?>
<tr><td align=”right” colspan=”10″><input type=”submit” name=”Submit” value=”Activate” class=”button” onClick=”return del_prompt(this.form,this.value)” />
<input type=”submit” name=”Submit” value=”Deactivate” class=”button” onClick=”return del_prompt(this.form,this.value)” />
<input type=”submit” name=”Submit” value=”Delete” class=”button” onClick=”return del_prompt(this.form,this.value)” />
</td></tr>
</table>

</div>
</form>
</div>
<div style=”background-color:#006699; height:150px; width:100%; float:left; border:1px #000000 solid; border-bottom:10px solid #CC3300″></div>
</body>
</html>

——————————————————————

Create page action.php:-

<?php
session_start();
$con=mysql_connect(“localhost”,”root”,””) or die(“mysql is not connected”);
$database=mysql_select_db(“myproject”,$con) or die(“database is not connected”);
$arr =$_POST[‘checkbox’];
$Submit =$_REQUEST[‘value’];
if(count($arr)>0){
$str_rest_refs=implode(“,”,$arr);
if($Submit==’Delete’)
{

$sql=”delete from artists where id in ($str_rest_refs)”;
$result=mysql_query($sql);
if($result)
{
header(“Location:home.php”);
}
//executeUpdate($sql);
//$sess_msg=’Selected record(s) deleted successfully’;
//$_SESSION[‘sess_msg’]=$sess_msg;
}
elseif($Submit==’Activate’)
{
$sql=”update artists set status=’activate’ where id in ($str_rest_refs)”;
$result=mysql_query($sql);
if($result)
{
//echo “activate”;
header(“Location:home.php”);
}
//executeUpdate($sql);
//$sess_msg=’Selected record(s) activated successfully’;
//$_SESSION[‘sess_msg’]=$sess_msg;
}
elseif($Submit==’Deactivate’)
{

$sql=”update artists set status=’deactivate’ where id in ($str_rest_refs)”;
$result=mysql_query($sql);
if($result)
{
//echo “deactivate”;
header(“Location:home.php”);
}
//executeUpdate($sql);
//$sess_msg=’Selected record(s) deactivated successfully’;
//$_SESSION[‘sess_msg’]=$sess_msg;
}
}

else{
$sess_msg=”Please select check box”;
$_SESSION[‘sess_msg’]=$sess_msg;
header(“Location:home.php”);
exit();
}
//header(“Location: “.$_SERVER[‘HTTP_REFERER’]);
exit();

?>

Please follow and like us:
0

Add a Comment

Your email address will not be published. Required fields are marked *