In this article, we are going to learn “How to create Youtube Search Engine using jQuery“. It is a easy jQuery script which help you to create Youtube Search Engine. you can use this in your website to search video…
Expand +All Articles
Export Gmail Contacts in PHP
Hello! In this post i will show you how to export gmail contacts in PHP after entering the gmail credentials using google oauth2. It will display all google contacts of that particular Email account and also i will give you…
Expand +How to Import Excel To Mysql Database Using PHP
Hello friends, In this post we will learn about “How to import excel or csv file to MySQL database using PHP”. Before start this topic, i want to discuss the use of this function?. As you know that if we have 10…
Expand +How to insert data into database using HTML form
Hello, In this post we will learn about mysqli query to insert data into database using HTML form. For this process we have to required 2 files, one is HTML file and another is php file. HTML file is used…
Expand +How to insert data using MySQLi query in php
In this tutorial you will learn how to insert records in a table using MYSQLi query . Let’s start to create a INSERT INTO statement with values using MYSQLi Procedural and MYSQLi Object-oriented method. Here we are going to insert…
Expand +How to access database without login into cpanel from my domain name
Hello friends, In this post we will learn how to access phpMyAdmin database without cpanel login using my domain name. To access database with your domain name, we have to use the phpmyadmin package. Now, i am going to explain…
Expand +Different types of errors in php
E_ERROR: A fatal error that causes script termination E_WARNING: Run-time warning that does not cause script termination E_ALL: Catches all errors and warnings E_PARSE: Compile time parse error. E_NOTICE: Run time notice caused due to error in code E_USER_WARNING: User-generated…
Expand +Distance calculator between two places using google map API in php
Hello! In this post, you will learn how to calculate distance between two places using google map API in php.Here you will calculate by air distance between two countries. See below ..how to do it.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
<?php function getDistance($addressFrom, $addressTo, $unit){ //Change address format $formattedAddrFrom = str_replace(' ','+',$addressFrom); $formattedAddrTo = str_replace(' ','+',$addressTo); //Send request and receive json data $geocodeFrom = file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$formattedAddrFrom.'&sensor=false&key=AIzaSyBOMQKyG37IA6VhextrNpB0YxQnsR6Phys'); $outputFrom = json_decode($geocodeFrom); $geocodeTo = file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$formattedAddrTo.'&sensor=false&key=AIzaSyBOMQKyG37IA6VhextrNpB0YxQnsR6Phys'); $outputTo = json_decode($geocodeTo); //print_r($outputFrom); //Get latitude and longitude from geo data $latitudeFrom = $outputFrom->results[0]->geometry->location->lat; $longitudeFrom = $outputFrom->results[0]->geometry->location->lng; $latitudeTo = $outputTo->results[0]->geometry->location->lat; $longitudeTo = $outputTo->results[0]->geometry->location->lng; //Calculate distance from latitude and longitude $theta = $longitudeFrom - $longitudeTo; $dist = sin(deg2rad($latitudeFrom)) * sin(deg2rad($latitudeTo)) + cos(deg2rad($latitudeFrom)) * cos(deg2rad($latitudeTo)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.151; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344).' km'; } else if ($unit == "N") { return ($miles * 0.8684).' nm'; } else { return $miles.' mi'; } } if(isset($_REQUEST['cal'])) { $addressFrom = $_POST['addressfrom']; $addressTo =$_POST['addressto']; $distance = getDistance($addressFrom, $addressTo, "K"); } ?> <html> <head> <title>Distance Calculation </title> <style> * { margin: 0; padding: 0; } .container { width: 800px; margin: 0 auto; border: 0px green dashed; } p { text-align: center; margin-bottom: 15px; padding: 5px; font-size: 16px; } input { padding: 10px; width: 500px; font-size: 16px; border: 1px #003366 solid; } textarea { width: 500px; height: 150px; resize: none; font-size: 16px; padding: 10px; border: 1px #003366 solid; } </style> <link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBOMQKyG37IA6VhextrNpB0YxQnsR6Phys&libraries=places"></script> <script> var autocomplete; function initialize() { autocomplete = new google.maps.places.Autocomplete( /** @type {HTMLInputElement} */(document.getElementById('autocomplete')), { types: ['geocode'] }); google.maps.event.addListener(autocomplete, 'place_changed', function() { }); autocomplete = new google.maps.places.Autocomplete( /** @type {HTMLInputElement} */(document.getElementById('autocomplete1')), { types: ['geocode'] }); google.maps.event.addListener(autocomplete1, 'place_changed', function() { }); } </script> </head> <body onload="initialize()"> <div class="container" id="locationField"> <center> <h1>Distance: <?php if(isset($distance)) { echo $distance; } ?></h1> </center> <form action="" method="post"> <p> <input type="text" required placeholder="From" name="addressfrom" id="autocomplete" onFocus="geolocate()" /> </p> <p> <input type="text" required placeholder="To" name="addressto" id="autocomplete1" onFocus="geolocate()" /> </p> <p> <input type="submit" name="cal" value="Calculate"> </p> </form> </div> </body> </html> |
how to connect mysqli with php
MYSQLi Tutorial for Beginners – how to create MySQLi connection with php in simple and easy steps starting from basic to advanced level. To create connection 4 parameter is required : “hostname” , “username“, “password” and “database name” see below..how…
Expand +How to write connection class to mysql database using php
Hello! In this post, you will learn to how to write and test the OOP based connection class to mysql database using php. see below..how to do it.. connection.php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<?php /** @author tutorialswebsite *@ copyright 2016 */ class createDBConnection // create a class for make connection { var $host="localhost"; var $username="username"; var $password="password"; var $database="database name"; var $dbconn; function connectToDatabase() //specify the server details for mysql { $conn=mysql_connect($this->host,$this->username,$this->password); if(!$conn)//testing the connection { die("Cannot connect to the database"); }else{ $this->dbconn=$conn; echo "Connection established"; } return $this->dbconn; } function selectDatabase() // selecting the database { //use php inbuild function foer select database mysql_select_db($this->database); if(mysql_error()) // if error occured display the error message { echo "Cannot find the database".$this->database; } echo "Database Selected.."; } function closeConnection() // close the connection { mysql_close($this->dbconn); echo "Connection closed"; } } ?> |
Now you have create the database connection class let’s see…
Expand +