Deleting records

hi all,
i have created one form for inserting and deletion.
my database name is “test” table name is “emp” which contains three fields
namely empno,empname,desig.
i have inserted some 4 to 5 values for the above table.
i have not made emp no as primary key.
i have entered random number for empno.and some values for empname and desig.
below is for insert is “new1.php”


<?php
 function checkform($empno,$empname,$desig,$error)
 {
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
 <title>New Record</title>
 </head>
 <body>
 <?php 
 // if there are any errors, display them
 if ($error!= '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 
 <form action="" method="post">
 <div>
 <strong>EmpNo: </strong> <input type="text" name="empno" value="<?php echo $empno; ?>" /><br/>
 <strong>EmpName: </strong> <input type="text" name="empname" value="<?php echo $empname; ?>" /><br/>
 <strong>Desig: </strong> <input type="text" name="desig" value="<?php echo $desig; ?>" /><br/>
 <input type="submit" name="submit" value="Submit">
 </div>
 </form> 
 </body>
 </html>
 <?php 
 }
  include('connect_db1.php');
  if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
 $empno =mysql_real_escape_string($_POST['empno']);
 $empname = mysql_real_escape_string($_POST['empname']);
 $desig = mysql_real_escape_string($_POST['desig']);
  
 if ($empno == '' || $empname == '' || $desig == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';
 
 // if either field is blank, display the form again
 checkform($empno,$empname,$desig,$error);
 }
 else
 {
  mysql_query("INSERT emp SET empno='$empno', empname='$empname',desig='$desig'")
 or die(mysql_error()); 
  header("Location: view1.php"); 
 }
 }
 else
  {
 checkform('','','','');
 }
?> 

below is “connect_db1.php”


<?php
 $connection = mysql_connect("localhost","root","")
 or die ("Could not connect to server ... \
" . mysql_error());
 mysql_select_db("test")
 or die ("Could not connect to database ... \
" . mysql_error());
?>

i am unable to delete the records .
kindly tell me how to delete the records in my table.this is with out autoincrement.
below is my “delete1.php”


<?php
 // connect to the database
 include('connect_db1.php');
 if (isset($_POST['empno'])) /*&& is_numeric($_POST['empno'])) */
 {
 $empno = $_POST['empno'];
 $result = mysql_query("DELETE FROM emp WHERE empno=$empno")
 or die(mysql_error()); 
 header("Location:view1.php");
 }
 else
 {
 header("Location:view1.php");
 }
?>

i have also have “view1.php”


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View Records</title>
</head>
<body>

<?php
 include('connect_db1.php');
 $result = mysql_query("SELECT * FROM emp") or die(mysql_error());  
 echo "<table border='1' cellpadding='10'>";
 echo "<tr> <th>EmpNo</th> <th>EmpName</th> <th>Desig</th> <th></th> </tr>";
// loop through results of database query, displaying them in the table
 while($row = mysql_fetch_array($result)) 
{        
// echo out the contents of each row into a table
    echo "<tr>";
    echo '<td>' . $row['empno'] . '</td>';
    echo '<td>' . $row['empname'] . '</td>';
    echo '<td>' . $row['desig'] . '</td>';
    echo '<td><a href="delete1.php?empno=' . $row['empno'] . '">Delete</a></td>';
    echo "</tr>"; 
} 
    // close table>
    echo "</table>";
?>
<p><a href="new1.php">Add a new record</a></p>
</body>
</html> 

please tell me how to delete the records…

You are using


<a href="delete1.php?empno=' . $row['empno'] . '">Delete</a>

but trying to access it using


 $empno = $_POST['empno'];

. You are not passing the empno by POST, you are passing it by GET.

do u mean like this one.


<a href="delete1.php?$empno = $_POST['empno'] . '">Delete</a>

whether is it possible to delete random number values in php

what i mean instead of


 if (isset($_POST['empno'])) /*&& is_numeric($_POST['empno'])) */
 {
 $empno = $_POST['empno'];

it should be


 if (isset($_GET['empno'])) 
 {
 $empno = $_GET['empno'];

As long as empno is unique, you can use it to delete with.

hi,
in the above program i have been using links for adding a new record and for deleting.
is it possible to use button with name as “submit” there.
whether we have to use javascript or with out javascript also can we do.
is it possible?
if possible kindly tell me…