Hi, This is a code which shows all the records from database and also show EDIT and DELETE Button for each Record, Now I want only one DELETE Button for ALL Records and use check boxes to select and DELETE. Please Check this Code:
<?php
$server="localhost";
$user="root";
$pass="root";
$database="new";
$cmd=$_POST["cmd"];
$eno=$_POST["eno"];
$ename=$_POST["ename"];
$edate=$_POST["edate"];
$Longitude=$_POST["Longitude"];
$Lat=$_POST["Lat"];
$Address=$_POST["Address"];
$Region=$_POST["Region"];
$City=$_POST["City"];
$MaintainedBy=$_POST["MaintainedBy"];
$StatusNopatPat=$_POST["StatusNopatPat"];
$Priority=$_POST["Priority"];
# Connect to database
$cn=mysql_connect($server,$user,$pass);
if(!$cn) {
die ("<br/>DB not connnected : " . mysql_error());
}
# Select a database
$db=mysql_select_db($database,$cn);
if(!$db)
die(mysql_error() . " " . mysql_errno());
if(isset($cmd,$eno))
{
# --- When edit button press --------
if($cmd=="Edit") {
$res = mysql_query("SELECT * FROM Info
WHERE SiteId='$eno' ");
$r=mysql_fetch_row($res);
print<<<TTT
<form method="post" action="editdelete.php">
<br/>SiteID <input type="text" name="eno" value="$r[0]" />
<br/>Alias <input type="text" name="ename" value="$r[1]"/>
<br/>Code <input type="text" name="edate" value="$r[2]"/>
<br/>Long <input type="text" name="Longitude" value="$r[3]"/>
<br/>Lat <input type="text" name="Lat" value="$r[4]"/>
<br/>Address <input type="text" name="Address" value="$r[5]"/>
<br/>Region <input type="text" name="Region" value="$r[6]"/>
<br/>City <input type="text" name="City" value="$r[7]"/>
<br/>Maintained By<input type="text" name="MaintainedBy" value="$r[9]"/>
<br/>PAT Status<input type="text" name="StatusNopatPat" value="$r[10]"/>
<br/>Priority<input type="text" name="Priority" value="$r[15]"/>
<br/><input type="submit" name="cmd" value="Update"/>
<input type="submit" name="cmd" value="Cancel"/>
<hr/>
</form>
TTT;
}
# -- Delete a record --
if($cmd=="Delete") {
$sql = mysql_query("delete FROM Info
WHERE SiteId='$eno' ");
echo "Record deleted";
}
# -- Update a record --
if($cmd=="Update") {
/* $sql = mysql_query("UPDATE Info SET Alias='$ename',Code='$edate',Longitude='$Longitude',Lat='$Lat' where
SiteID='$eno' ");*/
$query=mysql_query("update Info set alias='$ename',code='$edate',Longitude='$Longitude',Lat='$Lat',Address='$Address',Region='$Region',City='$City',MaintainedBy='$MaintainedBy',StatusNopatPat='$StatusNopatPat',Priority='$Priority' where siteid='$eno'");
echo "Record updated";
}
}
# -- Show the list - Grid
$sql="select * from Info";
$res=mysql_query($sql,$cn);
if(!$res)
die ("<br/>" . mysql_error());
print "<table cellpadding=1 cellspacing=1 width=100% style=font-size:12px>";
print "<tr><th bgcolor=#5D9BCC>SiteID</th bgcolor=#5D9BCC><th bgcolor=#5D9BCC>Alias</th><th bgcolor=#5D9BCC>Code</th><th bgcolor=#5D9BCC>Long</th><th bgcolor=#5D9BCC>Lat</th><th bgcolor=#5D9BCC>Address</th><th bgcolor=#5D9BCC>Region</th><th bgcolor=#5D9BCC>City</th><th bgcolor=#5D9BCC>Maintained By</th><th bgcolor=#5D9BCC>PAT Status</th><th bgcolor=#5D9BCC>Priority</th><th bgcolor=#5D9BCC>Action</th></tr>";
while($r=mysql_fetch_array($res))
{
print "<tr bgcolor=#FEE9A9><form method='post' action='editdelete.php'>";
print "<td>$r[0]</td><td>$r[1]</td><td>$r[2]</td><td>$r[3]</td><td>$r[4]</td><td>$r[5]</td><td>$r[6]</td><td>$r[7]</td><td>$r[9]</td><td>$r[10]</td><td>$r[15]</td><td>";
print "<input type='hidden' value='$r[0]' name='eno'/>";
print "<input type='submit' name='cmd' value='Edit'/>";
print "<input type='submit' name='cmd' value='Delete'/>";
print "</td></form></tr>";
}
print "</table>";
mysql_close($cn);
?>
Please give me easiest way of doing this.
Like Hotmail Email Inbox when we checked many Emails we Simply press DELETE Button.