Skip to main content

Posts

Showing posts with the label PHP

Dynamically Adding Dropdown Options and Handling "Other" with Show/Hide Functionality

Dropdown menus are a crucial part of many web forms, providing users with predefined options to choose from. However, there are scenarios where users need to add new options or input custom values. This post outlines how to dynamically add options to a dropdown list using a text box and show or hide the text box when "Other" is selected. Dynamic Dropdown Option Addition Using JavaScript and Ajax, you can create a seamless experience for users to add new options dynamically. Below is the implementation: JavaScript Code for Dynamic Option Addition $ ( document ). on ( 'click' , '.btcl' , function () {     var dataString = 'Rule=comp_list' ;     $ . ajax ({         type : "POST" ,         url : "ajax.php" ,         data : dataString ,         cache : false ,         success : function ( data ) {             $ ( "#company_list" ). html ( dat...

Dynamic Dropdowns Made Simple: Update Child Menus Using jQuery Ajax

Dynamically Loading Child Dropdowns Using Parent Dropdown Selection Efficient management of dropdown menus is a common requirement in web development, especially when creating dynamic forms. This blog explores a simple and scalable approach to dynamically loading child dropdowns based on the selected option in parent dropdowns using a single jQuery Ajax function. Key Highlights of the Method Unified Ajax Call: A single Ajax function handles multiple dropdown relationships, reducing repetitive code. Dynamic Data Preparation: Based on the parent dropdown's ID, relevant data is passed to the server to fetch the required child dropdown options. Enhanced User Experience: Child dropdown options update instantly, ensuring responsiveness and interactivity. The JavaScript Solution Below is the JavaScript code using jQuery for dynamically updating child dropdowns: $ ( document ). ready ( function () {   // Unified Ajax Call for Dropdown Updates   $ ( '.rnscall' ). on ( 'chang...

How to Enable IMAP PHP in xampp

The imap extension comes as standard with the PHP installation. You just need to enable it in your php.ini   Enable IMAP in XAMPP: You need to configure your php.ini file to enable IMAP extension Search for the line ;extension=php_imap.dll and remove semicolon(;) and restart your xampp. The line should look like as mentioned below. extension=php_imap.dll Note : New php version does not have dll anymore. The default php.ini should already contain a line to load the extension but commented out: ;extension=imap Remove semicolon from above like below extension=imap Enable IMAP in Linux: If you are using LAMP server, First install IMAP using the command on terminal $ sudo apt-get install php5-imap To enable IMAP, run the following command. sudo phpenmod imap Restart apache server with below command sudo service apache2 restart

Simple PHP function to update data in Mysql Database

The below simple php function is used to update data into MySql database with out manually filling the update mysql query with input filed names. Function: function update_Defined($table, $data, $condition){     // update('table', array_map('trim',$_POST),'id='.$_POST['p_id']);     global $db;     $query = "UPDATE `" . $table . "` SET ";     $fis = array(); $vas = array();        foreach ($data as $field => $val){         $fis[] = "`$field`";         $vas[] = "'" . mysqli_real_escape_string($db,$val) . "'";     }        foreach ($fis as $key => $field_name) {         $fields[$key] = $field_name;         if (isset($vas[$key])) {             $fields[$key] .=...

Simple Function to Insert data into MySql database using PHP

The below simple php function is used to insert data into MySql database with out manually filling the insert mysql query with input filed names. Function: function insert_Defined($table, $array,$ins=''){   // insert('table', array_map('trim',$_POST));     global $db;     $query = "INSERT INTO" . ' ' . $table;     $fis = array(); $vas = array();         foreach ($array as $field => $val) {         $fis[] = "`$field`";         $vas[] = ($val != "NOW()") ? "'" . mysqli_real_escape_string($db,$val) . "'" : "NOW()";     }         $query .= "(" . implode(",", $fis) . ") VALUES (" . implode(",", $vas) . ")";     //echo $query;exit;     Query($query);if(!empty($ins)){$ins_id=mysqli_insert_id($db);return $ins_id;} } Form: ...

Calculate Number of working days in a month excluding weekends(Saturday and Sunday) using PHP

The below function is used to calculate number of working days in a month. Function Calling: $no_days= rns_countDays ($row['date'],array(0, 6)); Function: function rns_countDays($date, $ignore) {      //echo countDays(array(0, 6), start_date, end_date);     $count = 0;     $ndays=0;     $now=date("Y-m-d");     $month=date("m",strtotime($date));     $year=date("y",strtotime($date));            if($month==date("m") && $year==date('y')) { //Date diff month start date to current date         $from_date = new DateTime($year.'-'.$month.'-01');         $to_date = new DateTime($now);         $days_diff=$from_date->diff($to_date); //echo $days_diff->d;         $ndays=$days_diff->format("%a");     ...

Get current filename with first parameter(Query String) from URL using PHP function

Today eabhyas come up with a Query String function. This function is useful to get the Query String from URL. This Function is used to get current filename with first parameter(Query String) from URL using PHP function . Function: function rns_QueryString_first($incomingURL){     preg_match('/[^&]+/', $incomingURL, $match);     return $outgoingURL = $match[0]; } Example: $path="property_add?id=3&aa=aa&b=123"; define('RNSFIFQ', rns_QueryString_first($path)); echo RNSFIFQ; Output: property_add?id=3

Remove Duplicate QueryStrings from URL using PHP

This simple PHP function is used to Remove Duplicate QueryStrings from URL. Function: function rnsQueryString_dupremov($qstring){     if(!empty($qstring)) {     $vars = explode('&', $qstring);     $final = array();     if(!empty($vars)) {         foreach($vars as $var) {             $parts = explode('=', $var);                 $key = $parts[0];             if(!empty($parts[1])) { $val = $parts[1]; } else {$val="";}                 if(!array_key_exists($key, $final) && !empty($val))                 $final[$key] = $val;         }     }     return...

EBS Payment Gateway PHP integration kit - Version 3-PHP Integration kit

New EBS Version 3 Integration kit , based on PHP platform, can be downloaded from the following link: https://support.ebs.in/app/ind ex.php?/default_import/Knowled gebase/Article/View/620/29/ version-3-php-integration-kit Integration Guide can be downloaded through: https://support.ebs.in/app/ind ex.php?/Knowledgebase/Article/ View/651/29/ebs_integration_ guide_301 To fetch your secret key kindly login to your merchant console panel ( secure.ebs.in ) and navigate to Account >> Settings. (Login credentials will be automatically triggered to registered email id, once the account is made LIVE from our end) Kindly note that by default your EBS account is configured to use SHA512 as the hashing algorithm in the payment page template. Method to calculate the hash for request parameters: MD5/SHA1/SHA512: Hash should be calculated for all posting parameters along with your secret key. First, all the posting parameters should be sorted in ascending order and then with the secret ke...

Populate Dropdown List with Array Values in PHP

The below PHP function used to Populate HTML Dropdown List from Array Values. Function : <?php function rnsdrop_Array($arr,$selids,$title='Select'){     print"<option value='0'>".$title."</option>";     foreach($arr as $id =>$name) {     if($selids==$id && $id!=0)         print "<option value=\"".$id."\" selected>".stripslashes($name)."</option>\r\n";     else if($id!=0)         print "<option value=\"".$id."\">".stripslashes($name)."</option>\r\n";     } } ?>   The below example explains how to generate dropdown list with array values using simple PHP function.   Example: <?php $arr=array(0=>'-',1=>'East','West','North','South'); rnsdrop_Array($prop_facing, @$row['prop_facing'],"Select Property Fac...

How to create a Barcode Using PHP Barcode 128 Generator

A barcode is an optical, machine-readable, representation of data, the data usually describes something about the object that carries the barcode.We will use PHP to generate Barcode in this tutorial. In this script, we are using coding which will generate barcodes in barcode format Code 128 . First, we will create index.php which will ask for the user input for which Barcode has to be created PHP Barcode Generator <fieldset><legend>Detail Informations</legend><form action="createbarcode.php" method="post"><b>Enter Your Code </b><input name="barcode" type="text" /><input type="submit" value="Create Barcode" /></form></fieldset> Now we will create createbarcode.php which will call function from Barcode code128 class for creating barcode <? php include('barcode128.php'); // include php barcode 128 class // design our barcode display echo...

Common MySql Interview Questions and Answers For Experienced/Freshers

Some Common MySql Interview Questions and Answers For Experienced + Freshers Which mostly asked my interviewer during interview session, As you know MySql is highly popular relational database and good compatible with open source languages like PHP. Following list of basic Mysql question and answer surely help developers for getting new jobs. MySql Interview Questions and Answers Question: What is MySQL? MySQL is an open source relational database management system (RDBMS) that uses Structured Query Language, the most popular language for adding, accessing, and processing data in a database. Because it is open source, anyone can download MySQL and tailor it to their needs in accordance with the general public license. MySQL is noted mainly for its speed, reliability, and flexibility.   Question: Why MySQL is used? MySQL database server is reliable, fast and very easy to use. This software can be downloaded as freeware and can be downloaded from the internet   Ques...