如何在删除之前将详细信息插入到其他表中

时间:2013-11-11 06:52:51

标签: php mysql

我需要一些帮助..我希望有人可以帮助我=')..是关于删除进程..删除之前我希望细节将首先保存到其他表..但我不知道如何在删除之前将详细信息插入“departmenttrail”表。下面是我的代码..但是这段代码不起作用,希望有人可以提供帮助..

 <?php
    session_start();
    $popo=$_SESSION['userID'];
    include('Connections/dbconn.php');
    if(isset($_SESSION['userID']) && $_SESSION['userID'] != ""){


    ?>
    <?php require_once('Connections/dbconn.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }

    if ((isset($_GET['valid'])) && ($_GET['valid'] != "")) {

    $inserted_id = $_GET['valid'];

    $sql2 = mysql_query("INSERT INTO departmenttrail (d_no,d_name, d_position, d_staff_name, d_noic_nopassport, d_type_training, d_date_training, d_date_expired, d_sijil) SELECT * FROM department WHERE d_no =".$inserted_id) or die("Error: " . mysql_error());

      $deleteSQL = sprintf("DELETE FROM department WHERE d_no=%s",
                           GetSQLValueString($_GET['valid'], "int"));

      mysql_select_db($database_dbconn, $dbconn);
      $Result1 = mysql_query($deleteSQL, $dbconn) or die(mysql_error());

        print '<script type="text/javascript">'; 
        print 'alert("The details are successfully deleted")'; 
        print '</script>';
        echo "<script language=\"JavaScript\">{                                                                                         
        location.href=\"update(power).php\"                                                                                         
        }</script>";
      if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $deleteGoTo));
      insertAuditTrail(date('Y-m-d H:i:s'),"Module:Delete User" ,"User Details successfully deleted",$_SESSION['userID']); 
    }
    ?>
    <?php 
    }
    else{
        header("Location: index.php");}

    ?>

0 个答案:

没有答案