Tuesday, January 21, 2025

Get the Selected Value from Dropdown on Button Click in Angular

Requirement:

1. Get the Selected Value from Dropdown on Button Click in Angular

2. Disabled the dropdown once form submitted

3. Show Selected Value below after form Submitted

Solutions:

To achieve the functionality where dropdown fields are disabled, and their selected values are shown below after clicking the "Submit for Approval" button in Angular, you can implement it as follows:

Example Angular Code

HTML: Template file

<div *ngFor="let item of records">

  <label>{{ item.label }}</label>

  <select [(ngModel)]="item.selectedValue" [disabled]="isSubmitted">

    <option *ngFor="let option of item.options" [value]="option.value">

      {{ option.label }}

    </option>

  </select>

  <div *ngIf="isSubmitted">

    <p>Selected Value: {{ item.selectedValue }}</p>

  </div>

</div>

<button (click)="submitForApproval()">Submit for Approval</button>


TypeScript Code:

import { Component } from '@angular/core';

@Component({

  selector: 'app-records-management',

  templateUrl: './records-management.component.html',

  styleUrls: ['./records-management.component.css'],

})

export class RecordsManagementComponent {

  isSubmitted = false;

  records = [

    {

      label: 'Does your system store Records?',

      options: [

        { label: 'Yes', value: 'yes' },

        { label: 'No', value: 'no' },

      ],

      selectedValue: null,

    },

    {

      label:

        'Do you know angular?',

      options: [

        { label: 'Yes', value: 'yes' },

        { label: 'No', value: 'no' },

      ],

      selectedValue: null,

    },

  ];

  submitForApproval() {

    this.isSubmitted = true;

  }

}

Explanation

1. Dropdown Binding: The select element is bound to each item's selectedValue property using Angular's two-way binding ([(ngModel)]).

2. Disable Dropdown: When isSubmitted is true, the disabled property is applied to the dropdown.

3. Show Selected Value: After submission, the selected values are displayed below the dropdown using *ngIf="isSubmitted".

4. Submit Button: Clicking the "Submit for Approval" button sets isSubmitted to true, disabling the dropdowns and showing the selected values.

Tuesday, March 26, 2019

Import CSV File Data into MySQL Database using PHP Demo

  • Create Database & Table

1. Create a database name as : phpsamples
2. Run Below code for creating a table

File name : users.sql

CREATE TABLE IF NOT EXISTS `users` (
  `userId` int(8) NOT NULL,
  `userName` varchar(55) NOT NULL,
  `password` varchar(55) NOT NULL,
  `firstName` varchar(255) NOT NULL,
  `lastName` varchar(255) NOT NULL
)

  • Create CSV File Format

File name : inputCSV.csv

1,kevin_tom,kevin,Kevin,Thomas
2,vincy,vincy,Vincy,Jone
3,tim_lee,tim,Tim,Lee
4,jane,jane,Jane,Ferro

  • Create index file
File name : index.php 

<?php
$conn = mysqli_connect("localhost", "root", "", "phpsamples");

if (isset($_POST["import"])) {
    
    $fileName = $_FILES["file"]["tmp_name"];
    
    if ($_FILES["file"]["size"] > 0) {
        
        $file = fopen($fileName, "r");
        
        while (($column = fgetcsv($file, 10000, ",")) !== FALSE) {
            $sqlInsert = "INSERT into users (userId,userName,password,firstName,lastName)
                   values ('" . $column[0] . "','" . $column[1] . "','" . $column[2] . "','" . $column[3] . "','" . $column[4] . "')";
            $result = mysqli_query($conn, $sqlInsert);
            
            if (! empty($result)) {
                $type = "success";
                $message = "CSV Data Imported into the Database";
            } else {
                $type = "error";
                $message = "Problem in Importing CSV Data";
            }
        }
    }
}
?>
<!DOCTYPE html>
<html>

<head>
<script src="jquery-3.2.1.min.js"></script>

<style>
body {
font-family: Arial;
width: 550px;
}

.outer-scontainer {
background: #F0F0F0;
border: #e0dfdf 1px solid;
padding: 20px;
border-radius: 2px;
}

.input-row {
margin-top: 0px;
margin-bottom: 20px;
}

.btn-submit {
background: #333;
border: #1d1d1d 1px solid;
color: #f0f0f0;
font-size: 0.9em;
width: 100px;
border-radius: 2px;
cursor: pointer;
}

.outer-scontainer table {
border-collapse: collapse;
width: 100%;
}

.outer-scontainer th {
border: 1px solid #dddddd;
padding: 8px;
text-align: left;
}

.outer-scontainer td {
border: 1px solid #dddddd;
padding: 8px;
text-align: left;
}

#response {
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 2px;
    display:none;
}

.success {
    background: #c7efd9;
    border: #bbe2cd 1px solid;
}

.error {
    background: #fbcfcf;
    border: #f3c6c7 1px solid;
}

div#response.display-block {
    display: block;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
    $("#frmCSVImport").on("submit", function () {

    $("#response").attr("class", "");
        $("#response").html("");
        var fileType = ".csv";
        var regex = new RegExp("([a-zA-Z0-9\s_\\.\-:])+(" + fileType + ")$");
        if (!regex.test($("#file").val().toLowerCase())) {
            $("#response").addClass("error");
            $("#response").addClass("display-block");
            $("#response").html("Invalid File. Upload : <b>" + fileType + "</b> Files.");
            return false;
        }
        return true;
    });
});
</script>
</head>

<body>
    <h2>Import CSV file into Mysql using PHP</h2>
    
    <div id="response" class="<?php if(!empty($type)) { echo $type . " display-block"; } ?>"><?php if(!empty($message)) { echo $message; } ?></div>
    <div class="outer-scontainer">
        <div class="row">

            <form class="form-horizontal" action="" method="post"
                name="frmCSVImport" id="frmCSVImport" enctype="multipart/form-data">
                <div class="input-row">
                    <label class="col-md-4 control-label">Choose CSV
                        File</label> <input type="file" name="file"
                        id="file" accept=".csv">
                    <button type="submit" id="submit" name="import"
                        class="btn-submit">Import</button>
                    <br />

                </div>

            </form>

        </div>
               <?php
            $sqlSelect = "SELECT * FROM users";
            $result = mysqli_query($conn, $sqlSelect);
            
            if (mysqli_num_rows($result) > 0) {
                ?>
            <table id='userTable'>
            <thead>
                <tr>
                    <th>User ID</th>
                    <th>User Name</th>
                    <th>First Name</th>
                    <th>Last Name</th>

                </tr>
            </thead>
<?php
                
                while ($row = mysqli_fetch_array($result)) {
                    ?>
                    
                <tbody>
                <tr>
                    <td><?php  echo $row['userId']; ?></td>
                    <td><?php  echo $row['userName']; ?></td>
                    <td><?php  echo $row['firstName']; ?></td>
                    <td><?php  echo $row['lastName']; ?></td>
                </tr>
                    <?php
                }
                ?>
                </tbody>
        </table>
        <?php } ?>
    </div>

</body>

</html>

Note: Please download "jquery-3.2.1.min" and save into same folder

Friday, June 1, 2018

How to Hide Apache Server ETag Header Information Disclosure?

<Directory /usr/local/httpd/htdocs>
    FileETag MTime Size
</Directory>

However, most of the websites that we tested don't bother configuring their ETags,
so a simpler solution is to turn off ETags entirely and rely on Expires or Cache-Control
headers to enable efficient caching of resources. 
To turn off ETags, add the following lines to one of your configuration files in Apache 
(this requires mod_headers, which is included in the default Apache build):

Header unset Etag
FileETag none
Then Restart https services like below:-
service httpd restart

Thursday, May 4, 2017

What is use of header() function in php?

1. Header is used to redirect from current page to another:

header("Location: newpage.php");

2. Header is used to send HTTP status code.
header("HTTP/1.0 404 Not Found");

3. Header is used to send Send a raw HTTP header
header('Content-Type: application/pdf');

Saturday, April 29, 2017

Difference betwwen Single quotes vs Double quotes in PHP

Strings with double quotes

You can insert variables directly within the text of the string. The PHP parser will automatically detect such variables, convert their values into readable text, and place them in their proper places (this is called concatenating, funny word).  
<?php
 $name = "Peter";
 $age = 42
 echo "Hi, my name is $name and I am $age years old.";
?> 
Output : Hi, my name is Peter and I am 42 years old.

Strings with single quotes

The text appears as it is. When it comes to enclosing strings in PHP, single quotes are much stricter than double quotes. When you enclose a string with single quotes, PHP ignores all your variables. Plus, you are able to write double quotes inside the text without the need of the escape slash.

<?php
 $name = 'David';
 echo 'Hi, my name is $name "The Crazy" Jones.';
?>
 Output : Hi, my name is $name "The Crazy" Jones.

double quotes VS single quotes 

<?php
$s = "dollars";
echo 'This costs a lot of $s.'; // This costs a lot of $s.
echo "This costs a lot of $s."; // This costs a lot of dollars.
?>



 

Monday, April 24, 2017

PHP script for printing first 20 Fibonacci numbers .

<?php
$count = 0 ;
$f1 = 0;
$f2 = 1;
echo $f1." , ";
echo $f2." , ";
while ($count < 20 )
{
$f3 = $f2 + $f1 ;
echo $f3." , ";
$f1 = $f2 ;
$f2 = $f3 ;
$count = $count + 1;
}
?>

Display Prime Numbers Between two Intervals in C language.

#include <stdio.h>
int main()
{
    int low, high, i, flag;
    printf("Enter two numbers(intervals): ");
    scanf("%d %d", &low, &high);

    printf("Prime numbers between %d and %d are: ", low, high);

    while (low < high)
    {
        flag = 0;

        for(i = 2; i <= low/2; ++i)
        {
            if(low % i == 0)
            {
                flag = 1;
                break;
            }
        }

        if (flag == 0)
            printf("%d ", low);

        ++low;
    }

    return 0;
}