i can't figure out how to delete my records in php. my page displays all the records from the database, and i want to place a checkbox beside each record and the function delete. please help me.
code is
php code
<?php
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
//build query
$query="SELECT * FROM employee";
//Execute query
$qry_result = mysql_query($query) or die(mysql_error());
//Build Result String
$display_string = "<table border='2' cellpadding='3'>";
$display_string .= "<tr>";
$display_string .= "<th>First Name</th>";
$display_string .= "<th>Last Name</th>";
$display_string .= "<th>Qualification</th>";
$display_string .= "<th>Status</th>";
$display_string .= "<th>Delete</th>";
$display_string .= "</tr>";
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td>$row[Fname]</td>";
$display_string .= "<td>$row[Lname]</td>";
$display_string .= "<td>$row[Qualification]</td>";
$display_string .= "<td>$row[Status]</td>";
$display_string .= "<td><a href='remove.php'>DELETE</td>";
$display_string .= "</tr>";
}
$display_string .= "</table>";
echo $display_string;
?>
my html with ajax is
<html>
<head>
<title>SM PORTAL WEBSITE</title>
<meta http-equiv="Content-Type" content="text/html;">
<script src="validation.js" type="text/javascript"></script>
<SCRIPT language=JavaScript>
function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i] = makeArray.arguments[i];
}
function getFullYear(d) {
var y = d.getYear();
if (y < 1000) {y += 1900};
return y;
}
//var zone = "EDT";
var days = new makeArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months = new makeArray("January","February","March","April","May","June","July","August","September","October","November","December");
function format_time(t) {
var Day = t.getDay();
var Date = t.getDate();
var Month = t.getMonth();
var Year = t.getFullYear();
timeString = "";
timeString += days[Day];
timeString += ", ";
timeString += " ";
timeString += months[Month];
timeString += " ";
timeString += Date;
timeString += ", ";
timeString += " ";
timeString += Year;
return timeString;
}
</SCRIPT>
<link rel="stylesheet" href="styles.css" type="text/css">
<style type="text/css">
<!--
.style1 {
font-size: 14px;
font-weight: bold;
}
.style2 {font-size: 16px}
.style3 {font-size: 12px}
-->
</style>
</head>
<body bgcolor="#B49BCD" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#747AC6" vlink="#B49BCD">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td valign="top" height="84" background="images/header_fill.jpg"><img src="images/smheaderlogo.jpg" width="321" height="84"></td>
</tr>
<tr>
<td valign="top" height="22" background="images/blue_fill.gif" align="right">
<table width="220" border="0" cellspacing="0" cellpadding="0" height="22">
<tr>
<td width="37"><img name="blue_crn" src="images/blue_crn.gif" width="37" height="22" border="0"></td>
<td background="images/lt_blue_fill.gif" class="date" width="200">
<script language=JavaScript>
<!--
d = new Date();
document.write(format_time(d));
// -->
</script>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td width="140" bgcolor="#92A2E1" valign="top" align="center"> <br>
<table width="80%" height="228" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="links"> <p><a href="home.htm"><img src="images/square.gif" width="7" height="7" border="0"></a> HOME<br>
<br>
<a href="http://10.101.150.184/nagios/"><img src="images/square.gif" width="7" height="7" border="0"></a> NAGIOS<br>
<br>
<a href="http://10.101.150.184/cgi-bin/smokeping.cgi"><img src="images/square.gif" width="7" height="7" border="0"></a> SMOKE
PING <br>
<br>
<a href="http://10.101.160.59:9675/account/login"><img src="images/square.gif" width="7" height="7" border="0"></a> SPICEWORKS<br>
<br>
<img src="images/square.gif" width="7" height="7"> HELP
DESK <br>
<br>
<a href="humanresourcemanagement1.htm"><img src="images/square.gif" width="7" height="7" border="0"></a> HUMAN
RESOURCE MANAGEMENT</p>
<p><img src="images/square.gif" width="7" height="7"> NETWORK
RESOURCE MANAGEMENT</p></td>
</tr>
</table>
</td>
<td valign="top" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="30" height="100%">
<tr>
<td height="370" valign="top" bgcolor="#FFFFFF" class="text"><form name="form2" method="post" action="adminpro.php">
<p class="style1"> </p>
<p align="center" class="style1 style2"> </p>
<p align="center">
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var age = document.getElementById('Fname').value;
var wpm = document.getElementById('Lname').value;
var queryString = "?Fname=" + Fname + "&Lname=" + Lname;
ajaxRequest.open("GET", "searchajax.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
</p>
<form name='myForm'>
<p align="center">First Name:</p>
<p align="center">
<input type='text' id='Fname' />
</p>
<p align="center">Last Name:</p>
<p align="center">
<input type='text' id='Lname' />
</p>
<p align="center">
<input type='button' onclick='ajaxFunction()' value='Search' />
</p>
</form>
<div id='ajaxDiv'>
<div align="center">Your result will display here</div>
</div>
<p> </p>
<p>
<label></label>
</p>
</form>
<p> </p></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="140" bgcolor="#92A2E1" height="27"> </td>
<td align="right" height="27" bgcolor="#FFFFFF"><img name="footer_right" src="images/footer_right.gif" width="110" height="27" border="0"></td>
</tr>
<tr>
<td width="140" background="images/footer_fill.jpg" height="38"> </td>
<td align="right" height="38" background="images/footer_fill.jpg">
<table width="100%" border="0" cellspacing="0" cellpadding="0" background="images/footer_fill.jpg">
<tr>
<td valign="bottom" align="center" class="footer">Copyright ©
SM Mart Inc. All Rights Reserved.</td>
<td align="right" width="110"><img name="footer_right2" src="images/footer_right2.gif" width="110" height="38" border="0"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="140" height="10"> </td>
<td align="right" height="10"> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>