sesc
09-03-2007, 10:52 PM
I am having a form which displays a couple of values from database and a delete button which is used to delete that particular record. Below is the code that I am using, but I am unable to delete the record. Please help me to get the record deleted. Thanks in advance!
with the below php code I am displaying the username and password on the page along with a delete button
When clicked on the delete button I used a javascript function which takes me to another page where I am actually executing the delete record functionality. My problem is when I used input type as "button", I am expecting that the javascript function should get executed which is not happening now. If I use the input type as submit it is taking me to the next page which is specified in the action property. Here when button is clicked, first a confirm button should popup which should ask for the confirmation of the user. If the user continues, then the record should be deleted. If the user cancels, then control should be in the currentpage only.
<?php
@session_start();
include("dbconnect.php");
$nbr = $_GET['Nbr'];
$Query = "Select * from tab where nbr = $nbr";
$res = mysql_query($Query);
if(mysql_num_rows($res) >0)
{
$row = mysql_fetch_assoc($res);
Email : $row[eMail]";
$uname = "$row[uname]";
$pwd = "$row[pwd]";
}
?>
<html>
<head>
<script language="javascript" type="text/javascript" >
function deleteNbr()
{
if(confirm("This cannot be undone!"))
{
location.href = "DelRec.php";
}
}
</script>
</head>
<body>
<form name="deletefrm" method="POST" action="delrec.php">
<table>
<tr>
<td >username </td>
<td width="5">:</td>
<td><?php echo "$uname"?></td>
<td > </td>
<td >password:</td>
<td ><?php echo "$pwd"?></td>
<td><input name="delete" type="Submit" value="Delete " onClick="return deleteNbr();"/>
</td>
</tr>
</table>
</form>
</body>
</html>
with the below php code I am displaying the username and password on the page along with a delete button
When clicked on the delete button I used a javascript function which takes me to another page where I am actually executing the delete record functionality. My problem is when I used input type as "button", I am expecting that the javascript function should get executed which is not happening now. If I use the input type as submit it is taking me to the next page which is specified in the action property. Here when button is clicked, first a confirm button should popup which should ask for the confirmation of the user. If the user continues, then the record should be deleted. If the user cancels, then control should be in the currentpage only.
<?php
@session_start();
include("dbconnect.php");
$nbr = $_GET['Nbr'];
$Query = "Select * from tab where nbr = $nbr";
$res = mysql_query($Query);
if(mysql_num_rows($res) >0)
{
$row = mysql_fetch_assoc($res);
Email : $row[eMail]";
$uname = "$row[uname]";
$pwd = "$row[pwd]";
}
?>
<html>
<head>
<script language="javascript" type="text/javascript" >
function deleteNbr()
{
if(confirm("This cannot be undone!"))
{
location.href = "DelRec.php";
}
}
</script>
</head>
<body>
<form name="deletefrm" method="POST" action="delrec.php">
<table>
<tr>
<td >username </td>
<td width="5">:</td>
<td><?php echo "$uname"?></td>
<td > </td>
<td >password:</td>
<td ><?php echo "$pwd"?></td>
<td><input name="delete" type="Submit" value="Delete " onClick="return deleteNbr();"/>
</td>
</tr>
</table>
</form>
</body>
</html>