0

我做了一个程序,将删除数据库中的记录,它正在工作,但程序会自动删除记录而无需确认。我希望我的程序在删除之前先确认,我该怎么做?

内容功能码:

 //*********************************************************************
 function Content() 
{
    if(isset($_POST['btnAdd']))  //if in case 'Add Entry' button is click 
    {
        return DataEntryForm('');
    }
    else if(isset($_POST['btnSave'])) //if in case 'Save' button is click during adding new entry or editing
    {
        if($_POST['uname']=='')
        {
            return saveRecord();
        }
        else
        {
            return updateRecord();
        }
    }
    else if(isset($_GET['edituname'])) //if in case 'Edit' is click 
    {
        return DataEntryForm('Edit');
    }
    else if(isset($_GET['deluname']))  //if in case 'Delete' is click 
    {
        return deleteRecord();
    }
    else if(isset($_POST['btnSearch'])) //if in case 'Search' is click 
    {
        return viewRecord();
    }
    else
    {
        return viewRecord('');
    }

}

删除记录功能码:

//***************************************************
// delete record
//***************************************************
function deleteRecord()
{
    $uname=$_GET['deluname'];

    $sql = "DELETE FROM users WHERE UserName='$uname'";
    $result = mysql_query($sql) or die(mysql_error());



      //-------------------------------------------
      // Display notification if successful
      //-------------------------------------------
      $code = <<< htmlcode
          <br/>
          <br/>
          <p align="center" border=0 style="font-family:verdana,helvetica; font-size:15px; color:green"> 
                User successfully deleted.
          </p>
          <br/>
          <center>
            <form name="frmDataEntry" method="POST" action="" style="font-family:verdana,helvetica; font-size:12px;">
              <table border=0 style="font-family:verdana,helvetica; font-size:12px;">
                <tr>
                  <td>
                    <input type="submit" name="btnBack" value="&nbsp&nbsp&nbsp OK &nbsp&nbsp&nbsp" onClick ="frmDataEntry.action='DataEntry_List_Search.php'"/>                  
                  </td>
                </tr>
              </table>    
            </form>
          </center>
          <br/>
          <br/>
htmlcode;

    return $code;

}
4

2 回答 2

0

为您的表单尝试此操作并删除只有我在提交时在表单中添加了行

//***************************************************
// delete record
//***************************************************
function deleteRecord()
{
    $uname=$_GET['deluname'];

    $sql = "DELETE FROM users WHERE UserName='$uname'";
    $result = mysql_query($sql) or die(mysql_error());



      //-------------------------------------------
      // Display notification if successful
      //-------------------------------------------
      $code = <<< htmlcode
          <br/>
          <br/>
          <p align="center" border=0 style="font-family:verdana,helvetica; font-size:15px; color:green"> 
                User successfully deleted.
          </p>
          <br/>
          <center>
            <form name="frmDataEntry" method="POST" action="" onsubmit="return confirm('Do you really want to delete??');"> style="font-family:verdana,helvetica; font-size:12px;">
              <table border=0 style="font-family:verdana,helvetica; font-size:12px;">
                <tr>
                  <td>
                    <input type="submit" name="btnBack" value="&nbsp&nbsp&nbsp OK &nbsp&nbsp&nbsp" onClick ="frmDataEntry.action='DataEntry_List_Search.php'"/>                  
                  </td>
                </tr>
              </table>    
            </form>
          </center>
          <br/>
          <br/>
htmlcode;

    return $code;

}
于 2013-09-19T13:24:30.743 回答
0

调用代码在这里不可见,但通常您只需要一个 Javascript 确认()函数:

<form action="delete.php" onsubmit="return confirm('Do you really want to delete user?');">
于 2013-09-19T13:10:49.733 回答