SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cannot pass value in window.location in delete button

    Hi Good day!

    I have a delete button and now I got a problem in getting the employee id which i want to delete.

    here is my code:

    Code:
    <?php
        session_start();
        ob_start();
        date_default_timezone_set("Asia/Singapore");
        error_reporting(0);
        include 'connection.php';
        
    $save = isset($_POST['save']);
    $update = isset($_POST['update']);
    $delete = isset($_POST['delete']);
    
    
    if ($save)
    {
        $employee_id    = $_POST['employee_id'];
        $lastname       = $_POST['lastname'];  
        $firstname      = $_POST['firstname'];
        $middlename     = $_POST['middlename'];
        $process_id     = $_POST['process_id'];
        
        
        $check_empid = "SELECT COUNT(employee_id) AS employee_id FROM operators where employee_id = '$employee_id'";
        $res_emp_id = mysql_query($check_empid, $con);
        
         if(mysql_result($res_emp_id, 0, "employee_id") > 0)
         {
                $sysmessage = "Employee ID: $employee_id already exists.";
         }
         else
         {
        $sql_insert =
        "INSERT INTO operators
        (employee_id, lastname, firstname, middlename, process_id)
        VALUES
        ('$employee_id', '$lastname', '$firstname', '$middlename', '$process_id')";
        $res = mysql_query($sql_insert, $con);
        echo header("Location:operator.php");
         }
    
    }
    
    //----update code-----//
    
    if($update)
    {
        $employee_id    = $_POST['employee_id'];
        $lastname       = $_POST['lastname'];  
        $firstname      = $_POST['firstname'];
        $middlename     = $_POST['middlename'];
        $process_id     = $_POST['process_id'];
        
        $sql_update = "UPDATE operators SET employee_id = '$employee_id', lastname = '$lastname', firstname = '$firstname',
         middlename = '$middlename', process_id = '$process_id' WHERE employee_id = '$employee_id'";
        $res_update = mysql_query($sql_update, $con);
        echo header("Location:operator.php");
    }   
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <title>Operators List</title>
    <head>
    <link rel="stylesheet" type="text/css" href="op_report.css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
    
    <link rel="stylesheet" type="text/css" href="filtergrid.css" />
    <script language="javascript" type="text/javascript" src="tablefilter.js"></script>  
    <script language="javascript" type="text/javascript" src="tablefilter_all.js"></script>
    <script language="javascript" type="text/javascript" src="tablefilter_all_min.js"></script>
    
    
    
    <link rel="stylesheet" type="text/css"  href="prompt.css">
    <link rel="stylesheet" type="text/css"  href="notify.css">
    
    <script type="text/javascript" src="prompt.js"> </script>
    <script type="text/javascript" src="notification.js"> </script>
    <script type="text/javascript">
    
    //----auto complete process name---//
    $().ready(function() {
        $("#process").autocomplete("get_process_list.php", {
           width: 145,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#process").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        });
        });
    
    //------auto complete employee id----//
    $().ready(function() {
        $("#emp_id").autocomplete("get_op_data.php", {
           width: 145,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#emp_id").result(function(event, data, formatted) {
        $("#employee_id").val(data[0]);
        });
        
        $("#emp_id").result(function(event, data, formatted) {
            $("#lastname").val(data[1]);
        });
        
        $("#emp_id").result(function(event, data, formatted) {
        $("#firstname").val(data[2]);
        });
        
        $("#emp_id").result(function(event, data, formatted) {
        $("#middlename").val(data[3]);
        });
        
        $("#emp_id").result(function(event, data, formatted) {
        $("#process").val(data[4]);
        });
        
        });    
        
    /*AJAX*/
    function AJAX(){
            var xmlHttp;
            try{
                xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
                return xmlHttp;
                }
            catch (e){
                try{
                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
                    return xmlHttp;
                    }
                catch (e){
                    try{
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                        return xmlHttp;
                        }
                    catch (e){
                        alert("Your browser does not support AJAX!");
                        return false;
                        }
                    }
                }
            }
            
    //----clear data----//
    function clear_data()
    {
         document.getElementById('employee_id').value = '';
         document.getElementById('lastname').value = '';
         document.getElementById('firstname').value = '';
         document.getElementById('middlename').value = '';
         document.getElementById('process').value = '';
         document.getElementById('process_id').value = '';
         
    }
    //------delete---//
    
    function confirmation(id) {
        var answer = confirm("You wish to delete this information?")
        if (answer){
            
            var employee_id = document.getElementById('employee_id').value;
            
            alert(employee_id);
            window.location = "delete_operator.php?id=employee_id";
    
        }
        else{
           // alert("Your Event is Not Deleted")
        }
    }
            
    
    </script>
    </head>
    <body onload=document.getElementById("employee_id").focus();>
    <form name="operator_list" action="" method="post" autocomplete="off">
        <!--Tab List -->
    <div id="ddcolortabs">
    <ul>
    <li id="current"> <a href="operator.php" title="Operator's List"><span>Production Operators</span></a></li>
    <li> <a href="supervisor.php" title="Supervisor's List"><span>Production Supervisors</span></a></li>
    </ul>
    </div>
    <br/>
    <br/>
    <div>
    <?php
    if($sysmessage)
       {
        echo "<p style='text-align: center; color: #ff0000; font-weight: bold;'>$sysmessage</p>";
       }
     ?>
    </div>
    
    <div>
    <table>
    <tr>
    <td>Employee ID Search :</td>
    <td><input type="text" name="emp_id" id="emp_id" value=""></td>
    </tr>
    </table>
    </div>
    <!-- Fieldset for Operators Information-->
    <div id="operators_fieldset">
    <fieldset>
    <legend>Input Operators Information</legend>
    <table>
    <tr>
    <td>Employee ID: </td>
    <td><input type="text" name="employee_id" id="employee_id" value=""></td>
    <tr>
    
    <tr>
    <td>Lastname: </td>
    <td><input type="text" name="lastname" id="lastname" value=""></td>
    </tr>
    
    <tr>
    <td>Firstname: </td>
    <td><input type="text" name="firstname" id="firstname" value=""></td>
    </tr>
    
    <tr>
    <td>Middlename: </td>
    <td><input type="text" name="middlename" id="middlename" value=""></td>
    </tr>
    
    <tr>
    <td>Process: </td>
    <td><input type="text" name="process" id="process" value=""></td>
    </tr>
    </table>
    
    <input type="hidden" name="process_id" id="process_id" value="" />
    
    <center>
    <input type="submit" name="save" id="save" value="Save">
    <input type="submit" name="update" id="update" value="Update">
    <input type="button" name="delete" id="delete" value="Delete" onclick="confirmation();">
    <input type="button" name="clear" id="clear" value="Clear" onclick="clear_data();">
    </center>
    </fieldset>
    </div>
    </body>
    </html>
    and here is my delete_operator.php

    Code:
    <?php
    
        ob_start();
        date_default_timezone_set("Asia/Singapore");
        error_reporting(0);
        include 'connection.php';
        $$employee_id = $_POST["id"];
       $sql_delete = "DELETE FROM operators WHERE employee_id = '$employee_id'";
       echo $sql_delete;
       exit;
        $res_delete = mysql_query($sql_delete, $con);
        echo header("Location:operator.php");
    
    ?>
    when I tried to alert the value of employee_id he gets the value correctly but I got problem here:

    Code:
    window.location = "delete_operator.php?id=employee_id";
    it did not get the id .

    I can't figured out what's wrong in my code.

    I hope somebody can help me.

    Thank you

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,401
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    when I tried to alert the value of employee_id he gets the value correctly but I got problem here:

    Code:
    window.location = "delete_operator.php?id=employee_id";
    it did not get the id .
    What you need to do is this:
    Code JavaScript:
    window.location = "delete_operator.php?id=" + employee_id;
    which will concatenate the url string with the value of employee_id.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    What you need to do is this:
    Code JavaScript:
    window.location = "delete_operator.php?id=" + employee_id;
    which will concatenate the url string with the value of employee_id.
    Thank you. it works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •