Monday, 16 August 2021

PHP Script date Difference Example with Source code

PHP Script for Date Difference :

    PHP Date function are used to get current date and time.

            $today=date("Y-m-d");

            echo $today;


You can result 2021-08-16 


Update soon.....

Thursday, 28 June 2018

PHP File uploads example with Source Code

Easy File Uploads in PHP Application.

There are some simple steps, you can done file upload in PHP applications

Step 1 : 

Create your Form, Additionally add attributes in form element.

Step 2: 

When your form submits, action page will be redirected, that page received all form values

 receive normal form values as usual format $var=$_POST["formcontrolname"]; metods
Note 1:

This section Using ,PHP File uplaods, have there are 4 methods
$_FILE["file"]["name"]               // This is choosing filename
$_FILE["file"]["type"]                 // This file type, png,pdf,doc,jpg
$_FILE["file"]["size"]                 // this is file size , Its take KB, you can convert MB format
$_FILE["file"]["tmp_name"]       // This is temp file,

Note 2:

If you restricted, allow some format files only uploaded in server, you can check if condition file type is JPG then upload files,

if you restricted, allow some limit size files only uploaded in server, you can check  if condition file size is "1000KB" then upload files,

if your not check, that is any kind of files uploaded then , need not to check any conditions

Step 3:

Next create uploading file to save some directory or folder, that folder create in your root directory, and assign target file path with uploading filename,

$uploadfildir="../products/".$_FILE["file"]["name"];
$target_file = $uploadfildir;

Step 4:

Finally you can store values in database, write connection and query methods, if query executes, then file is uploaded in your server

use move_uploaded_file() method,

Step 5

Finish,



Source Code

The above steps are using below examples, you can copy paste run your server,

Create products folder in root directory in your server,

Create products table in mysql, 

then create forms,

product.php

<form role="form" method="post" action="product_add.php" enctype="multipart/form-data">
   Category Name  <input type="text" name="categoryname"  placeholder="Enter Category Name">
   Product Name<input type="text" name="productname"  placeholder="Enter Product Name">
   Product Picture<input type="file" name="file"   placeholder="Choose file Name">
    <input type="submit" name="submit" value="ADD PRODUCT" class="btn btn-default"/>    
</form>


in action page, receive all form values, and store mysql table, and file uploaded in products folder,

product-save.php


<?php
$categoryname=$_POST["categoryname"];
$productname=$_POST["productname"];
$pic="JS-".$productname."-".$_FILES["file"]["name"];
$uploadfildir="../products/".$pic;
$target_file = $uploadfildir;
include("config.php");
 $insertsql="insert into products values('','$categoryname','$productname','$productpic')";
 $insertsqlres=mysqli_query($con,$insertsql);
 if($insertsqlres)
{
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file))
   {
echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
   }
}
else
{
echo "Products not added!";
}
?>


Monday, 25 June 2018

PHP- How to convert PHP application to exe (Windows Application)

Hi Dear friends

Many more websites and blogs and forums to check more option for PHP application is convert into desktop application..That time we have more doubts and more questions comes out in mind.. 

A most peoples strongly challenged "PHP to EXE Conversion is Possible ot Not?" 

A Result is "Not"

Its most peoples sharing as for reason is, PHP is scripting language, to make web based application,  Not a desktop application.

But We can use PHP application both Desktop and Web Based 


Here am explained PHP Application is used to Desktop mode, in following steps

Step 1 :

Create your PHP application, and Testing your Xampp server,

Step 2 :

To Set Xampp server is Automatic Running Mode, Bcoz when your system starts, server also started,

Step 3

Copy Paste Google Chrome browser in your desktop,

Next right click, icon properties, and open properties window, in target section in end of line,




to set --app=http://localhost/yourPHPprojectname/

After to change icon, 

Step 4:

Finally you click that icon,your PHP application working in EXE format, Its look like window application, No URLS, Address section, etc


Thank you.. we will see another important topics



PHP- Step by Step To Store and Retrieve Tamil Fonts in PHP and MySQL?

PHP- How to Store and Retrieve Tamil Fonts in PHP and MySQL?


In this post explained for how to store and retrieved tamil fonts in PHP and MySQL database.  here explain step by step

Previous post explained how to display tamil fonts in webpage in detailed.. that way first design in form in your webpage

Step 1: Design form in your (HTML ) Webpage


Step 2 :   Below code copy and save customers.php



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h2>Add New Customers</h2>
  <form name="customer" method="post" action="customers-add.php">
        <table>
         <tr><td>பெயர் </td><td><input type="text" name="cname" required /></td></tr>
        <tr><td>தொழில் </td><td><input type="text" name="occupation" required/></td></tr>
        <tr><td>விலாசம் </td><td><input type="text" name="address" required/></td></tr>
         <tr><td>ஊர் பெயர்  </td><td><input type="text" name="city" required/></td></tr>
        <tr><td>கைபேசி எண்  </td><td><input type="text" name="mobile" required/></td></tr>
        
        <tr><td></td><td><input type="submit" name="submit" value="SAVE CUSTOMER" /></td></tr>
        </table>
        </form>
</body>
</html>






Step 3 : 

Create Table in MySQL Database, just fieldname, length, additional SET as collation is
utf8_general_ci





Step 3 : 

Tables created successfully then go to coding action page


Step 4: 

Action page customers-add.php

<?php       
                 $cname=$_POST["cname"];
$occupation=$_POST["occupation"];
$address=$_POST["address"];
$city=$_POST["city"];
$address1=$address.",".$city;
$mobile=$_POST["mobile"];
$cusid=$branchcode."-$cname";

include("config1.php");
$q="insert into customers values('','$cname','$occupation','$address1','$mobile')";
$r=mysqli_query($link,$q);
if($r)
{
echo "<h3>கஸ்டமர் தகவல் பதிவு செய்யப்பட்டது !</h3>";
}
else
{
echo "<h3>கஸ்டமர் தகவல் பதிவு செய்ய முடியவில்லை  ! மன்னிக்கவும் </h3>";

}

?>



இந்த பதிவு பயன் உள்ளதாக இருக்கும் என நம்புகிறேன் ! நன்றி 



Sunday, 24 June 2018

PHP-How to Display Tamil Fonts in HTML Page?

How to Display Tamil Fonts in HTML Page?


Hi friends, this post for Tamil peoples,  

In normall html does not allow tamil fonts in webpage,  

So our tamil fonts displayed in webpage, just we set meta tag in UTF-8,

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>நண்பர்களுக்கு வணக்கம் </h1>
</body>
</html>



தமிழில் எழுதுங்கள் உங்கள் வலைப்பக்கத்தை  நன்றி !!!!!

PHP- How to find Due dates in PHP and MySQL?

Hi Dear friends,
In This post we see, how to find next due date in easily.

PHP- How to find next due dates in PHP and MySQL?


for example, Finance Management application need to calculated next number due dates, 
Just analysis, what we do?
Step 1: Just given date to add number of days then we get next due date,

for example, 20/06/2018 is given date, 30 days after next First due date then just 30 Days, add next 60 days then we get second due date etc,

In additionally,

Given Loan Date : 20/06/2018
I Due Date : 20/07/2018
II Due Date : 20/08/2018
II Due Date : 20/09/2018

The above example, solved below code, Its very simple logic and easily use to your application.

Loan Date is Current Date then you can use below code


$loandate=date("d/m/Y");

else

You are using HTML5 Date control, then control return default format, so we convert to needed format in below format,

$timestamp = strtotime($loandate);
$lldate = date("d/m/Y", $timestamp);

$duedateinterval=30; // Assign how many date intervals. 1 month then 30, 1 week then 7

$nm=0;
for($i=1;$i<=5;$i++)
{
$nm=$nm+$duedateinterval;
echo $i."Due Date is=".date('d/m/Y', strtotime("+$nm days"));
}


Enjoy! Use code.. If any doubts comments here


PHP- DataAdd methods in PHP?

How to Add to dates in PHP?

Simply example here explain, how to add two dates.

Just assign two dates in two variables

Manual Method

$d1="26/06/2018";
$d2="28/06/2018";
$sec=$d1-$d2; //Its returns in seconds, 
// To convert in Days
$days = $secs / 86400;
echo $days;


Result /Output is

-2 days

Find date difference between given to current date

Runtime Method

$inputdate=$_POST["gdate"]; // Its comes from form, i.e its the given input date
$d1=strtotime($loandate);    // Format to the date
$d2=strtotime(date("Y-m-d")); // Its Current date
$secs = $d1 - $d2;// == return sec in difference
$days = $secs / 86400
echo $days;


Thanks,

Next post we see another issues in PHP







Wednesday, 15 June 2016

Easy Making AJAX Grid Using PHP MySQL- Example Source Code

PHP GRID DEMO USING AJAX

AJAX GRID Using PHP -MySQL

Source Files


  1. grid.php
  2. getProduct.php
  3. Config.php


grid.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AJAX GRID DEMO</title>
<style>
#page{ width:400px; background:#F5F5F5; margin:0 auto}
h2{ color:#000033}
#updateArea{ width:400px; margin:0 auto}
table.grid {
width:100%;
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.grid th {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: #666666;
background-color: #F7F7F7;
}
table.grid td {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<script>
function getProduct() 
{

var xhttp;
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200)
{
      document.getElementById("updateArea").innerHTML = xhttp.responseText;
     }
    };
    xhttp.open("GET", "getProduct.php", true);
    xhttp.send();
}
</script>
</head>

<body>
<div id="page">
<h2 align="center">AJAX GRID DEMO</h2>
<p align="center"><input type="submit" name="submit" value="LOAD DATA" onclick="getProduct()" /></p>

<div id="updateArea">
<hr />
Grid Uplaoded
<hr />
</div>
<p align="center">AJAX Grid Demo</p>
</div>
</body>
</html>

getProduct.php

<?php

include("config.php");
$gq="select *from productmaster";
$gqres=mysqli_query($con,$gq);
$sno=1;
echo "<table class='grid'>";
echo "<tr>";
echo "<th>S.NO</th>";
echo "<th>PRODUCT ID</th>";
echo "<th>PRODUCT NAME</th>";
echo "</tr>";
while($gqrow=mysqli_fetch_array($gqres))
{
$sno=$sno+1;
echo "<tr>";
echo "<td>".$sno."</td>";
echo "<td>".$gqrow["productid"]."</td>";
echo "<td>".$gqrow["productname"]."</td>";
echo "</tr>";
}
echo "</table>";

?>

config.php

<?php
$con=mysqli_connect("localhost","root","","griddemo");
if(mysqli_connect_errno())
{
echo "Failed".mysqli_connect_error();
}
?>

The above code output is


Before Loaded Grid Demo

After Loaded Grid Demo




Any issues or problem to run please leave your comment section i will help to run..


Thank You!

AJAX with PHP-MySQL Example source code

Hai Friends..

In this section we will see following topics

How to use AJAX-PHP?
How to use AJAX-ASP.Net?
How to use AJAX-JSP?

Am explain single files and explain how to use AJAX in PHP,ASP.Net and JSP... Its very easy to understand and you can use AJAX in any kind of Server Side Scripting like PHP,ASP,JSP...

AJAX with PHP-MYSQL

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AJAX-PHP MYSQL EXAMPLE </title>
<style>
#container{ width:900px; margin:0 auto;}
#header{ width:100%; height:75px; background-color:#FFCC00; border-bottom:3px solid #FF6600}
#header h1{ color:#FF0033; padding-top:20px;}
#search{ width:100%; height:60px; padding-top:20px; text-align:right}
#content{ width:100%;}
#leftcontent{ width:70%; float:left;}
#updateArea { width:100%; border:1px solid #666666;}
#updateArea p{ padding:10px;}
#rightcontent{ width:25%; float:left}
#footer{ width:100%; height:30px; background:#FFCC00; border-top:3px solid #FF6600}
</style>
<script>
function getResult() 
{
var searchkey=document.getElementById("searchkey").value;
var xhttp;
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200)
{
      document.getElementById("updateArea").innerHTML = xhttp.responseText;
     }
    };
    xhttp.open("GET", "search.php?searchkey="+searchkey, true);
    xhttp.send();
}
</script>
</head>

<body>
<div id="container">
<div id="header"><h1>AJAX-PHP MySQL DEMO</h1></div>
<div id="search">
Search Keywords
<input type="text" id="searchkey" style="width:300px; padding:3px; border:1px solid #0099CC" />
<input type="submit" name="submit" value="SHOW RESULT" onclick="getResult()" />
</div>
<div id="content">
<div id="leftcontent">
<h3>Welcome to AJAX Example</h3>
<div id="updateArea">
<p>AJAX is a technique for creating fast and dynamic web pages.

AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

Classic web pages, (which do not use AJAX) must reload the entire page if the content should change.

Examples of applications using AJAX: Google Maps, Gmail, YouTube, and Facebook.</p>
</div>
</div>

<div id="rightcontent">
<h2>AJAX Tutorials</h2>
<ul>
<li>AJAX Introduction</li>
<li>AJAX Working</li>
<li>AJAX Methods</li>
<li>AJAX Examples</li>
<li>AJAX PHP</li>
<li>AJAX ASP</li>
<li>AJAX JSP</li>
</ul>
<br />
<img src="images/Ajax-programing.jpg" />
</div>
</div>
<div style="clear:both"></div>
<div id="footer">
AJAX Tutorials
</div>
</div>
</body>
</html>


search.php

<?php
$searchkeyword=$_GET["searchkey"];

echo "<h2>Your Search Keyword is</h2>";
echo $searchkeyword;

?>


the above code copy paste and save index.php and  search.php in your server and run the script.. you get following output.

Explanation:

The above code run your web server.. you get above output.. 
that page you enter any keyword in search box 
and click the show result button... 
the getResult() function will be called in run time..
The js function first we get run time input in document.getElementById("searchkey").value method.
that input received and store the variable searchkey
     
         var searchkey=document.getElementById("searchkey").value;

Next create XMLHttpRequest Object xhhtp
        var xhttp;
   xhttp = new XMLHttpRequest();
Next send the Request to a server like search.php with passing parameter like the way

      xhttp.open("GET", "search.php?searchkey="+searchkey, true);
       xhttp.send();

Next request send server page.. that page received coming parameter in following methods
       <?php
        $searchkeyword=$_GET["searchkey"];
       echo "<h2>Your Search Keyword is</h2>";
       echo $searchkeyword;

        ?>
Next Search.php response is Ready (That means onreadystatechange event state is 4) and search.php is found( its means page found status 200) the response is ready..
Next that response come back to browser, and updated particular part in without reloading the wholepage.
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200)
 {
          document.getElementById("updateArea").innerHTML = xhttp.responseText;
        }
       };


The output is
Note:

You can use same little bit change and you use ASP.NET and JSP

AJAX - ASP.NET
1. Just Change requested server page code

 xhttp.open("GET", "search.aspx?searchkey="+searchkey, true);
    xhttp.send();

2. in Received server page you received parameter in ASP.Net Code way
<%
       Dim searchkeyword As String=request.getParameter("searchkey")
       response.Write( "<h2>Your Search Keyword is</h2>")
       response.write(searchkeyword)
%>

AJAX - JSP

1. Just Change requested server page code

 xhttp.open("GET", "search.jsp?searchkey="+searchkey, true);
    xhttp.send();

2. in Received server page you received parameter in ASP.Net Code way
<%
       String searchkeyword As String=request.getParameter("searchkey");
       System.out.println( "<h2>Your Search Keyword is</h2>");
       System.out.println(searchkeyword);
%>

Easy and Simple AJAX Example Source Code

Hi friends

Simple AJAX Program Source Code

In This post give easy and basic simple ajax program source code. 
this code how to use ajax in webpage.

There are two page
1. Index.php (client Page)
2.getdata.php (Requested Server page)

Index.php 

<!DOCTYPE html>
<html>
<head>
<script>
function updateData()
 {
       var xhttp;
       xhttp = new XMLHttpRequest();
       xhttp.onreadystatechange = function()
        {
                 if (xhttp.readyState == 4 && xhttp.status == 200)
                   {
                 document.getElementById("updateAreapart").innerHTML = xhttp.responseText;
                   }
        };
  xhttp.open("GET", "getdata.php", true);
  xhttp.send();
}
</script>
</head>
<body>
<h3>Simple AJAX Program:</h3>
<input type="submut" name="submit" onlcick="updateData()">
<div id="updateAreapart">
</div>
</body>
</html>

getdata.php

<?php
echo "Hai welcome !";
echo "This is Server Response content";
?>

Explanation:

if you copy and paste above code and run the page.
First page runs display following output



When you click the button call javaScript function, the function we write js function..

that function started we give alert message box.. this check for javascript function call correct or wrong purpose.. finally this message we give commeneted line


after alert line.. we create XMLHttpRequest Object and Send Request and write onreadystatechange events..

Requested page getdata.php is available and response ready than updated area in body section the content will be updated that particular area without reloading the whole webpage.

you get following output without reloading the whole webpage

Note: AJAX Scripts only run Web Server.. does not run normal HTML way.. the above both files copy and paste XAMPP Server and run the scripts..

This is basic AJAX Program.. this you can understand you can make anything in your web application..
AJAX use many more situation to make good web apps
In personally we make more apps using AJAX Technology..

If anything doubt.. please give comment and contact my mail id..
Am ready to solve your problems 

Thank You!

Next section will come more live AJAX Example code and explanation..

keep it touch our blog!


Tuesday, 14 June 2016

Easy Learn AJAX- Beginners AJAX Tutorials Part 5- Server Response Method

Hi Friends

In this section will see that how to Server Response to browser(client) and what basics response come back to browser

AJAX Server Response to browser

There are two methods property in server response
1.responseText
2.responseXML



the above XMLHttpRequest object to get response data as  string than we can use above method in following way
             xhttp.responseText

the above XMLHttpRequest object to get response data as  XML than we can use above method in following way
            xhttp.responseText

Ok fine!

Then how to use this code in script and how to update particular part without reloading the whole webpage

document.getElementById("updateArea").innerHTML = xhttp.responseText;
document.getElementById("updateArea").innerHTML = xhttp.responseTextXML;

This above code inside the onreadystatechange event like it

xhttp.onreadystatechange = function()
 {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("updateArea").innerHTML = xhttp.responseText;
    }

  };

Next section will post Live time example scripts 

Thank You!

What is AI- Artificial Intelligence - தமிழில்

Artificial Intelligence : Artificial intelligence leverages computers and machines to mimic the problem-solving and decision-making capabili...