Rajat
Rajat

Reputation: 33

if else construct issue in value attribute of html

 public function getEmployeeId() {
        if (!isset($_SESSION["email"]) || !isset($_SESSION["passwrd"])) {
            header("Location:index.php");
            // Cannot Access this page without Login.
        }
        if (empty($_POST)){
            $_SESSION['ids'] = "";
            $query = mysqli_query($this->connection, "SELECT MAX(EmployeeId) AS EmployeeId FROM employees") or die("Query execution failed: " . mysqli_error());
            while ($row = $query->fetch_assoc()) {
                // Push the id to the array.
                $_SESSION['ids'] = $row["EmployeeId"];
            }
        }
    }

The above code snippet bring the latest registered employee ID from the database. ------------------------>--------------------

public function updateSalary(){
        if (!isset($_SESSION["email"]) || !isset($_SESSION["passwrd"])) {
            header("Location:index.php");
            // This code Snippet ensures that in order to access this page Employee needs to be Login.
        }
        $EmployeeID = (isset($_GET['EmployeeId']) ? $_GET['EmployeeId'] : '');
        $query = mysqli_query($this->connection, "SELECT * FROM salary WHERE EmployeeId= '" . $EmployeeID . "'") or die("Query execution failed: " . mysqli_error());
        while ($row = $query->fetch_assoc()){
            // Push the id to the array
            $_SESSION['eids'] = $row["EmployeeId"];
            $_SESSION['salry'] = $row["Salary"];
            if ($_SESSION['ids']) {
            $_SESSION['ids'] = "";
            }
        }

the above code snippet is my update function to update each record. And i have included both the above function in my html form at the top.

The Problem is that : As my insertion and updation form is same, so the session value which is in if statement is echoed in the text box , else part does not work even if session is unset in if part, What should i do ? See the below code

here is the value attribute :

 <td>
                   <input type="number" name="EmployeeId" placeholder="EmployeeId" value="<?php if (isset($_SESSION["ids"])){echo $id_salaries;}else{echo $emp_id;} ?>" id="EmployeeId" autocomplete="off" class="form-control" readonly>
                </td>  

Upvotes: 0

Views: 41

Answers (1)

JYoThI
JYoThI

Reputation: 12085

This is not session unset $_SESSION['ids'] = ""; this is your assigning empty string value to session . session unset should be unset($_SESSION['ids'])

Upvotes: 1

Related Questions