Difference between require() and require_once()?

php-training-in-gurgaon
The require() and require_once() functions perform same work. Both functions will include and evaluates the specific file while executing the code. if include() is not able to find a specified file on location at that time it will throw a warning however, it will not stop script execution. For the same scenerio require() will throw fatal error and it will stop the script execution. Example <?php echo "Hello"; ?> test.php <?php require('echo.php'); require_once('echo.php'); ?> test.php outputs: "Hello".
Read More

PHP and HTML interact?

php-training-in-gurgaon
PHP is an HTML-embedded server-side scripting language. The goal of the language is to allow web developers to write dynamically generated pages quickly. NTC Hosting offers its clients high quality PHP and HTML hosting services. Our servers are configured so as to ensure maximum performance for both your HTML and PHP-based applications and the non-interruptible functioning of your websites. Example <?php $Fname = $_POST["Fname"]; $Lname = $_POST["Lname"]; ?> <html> <head> <title>Personal INFO</title> </head> <body> <form method="post" action="<?php echo $PHP_SELF;?>"> First Name:<input type="text" size="12" maxlength="12" name="Fname"><br /> Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br /></form> <? echo "Hello, ".$Fname." ".$Lname.".<br />"; ?>
Read More

Multiple inheritance in PHP?

php-training-in-gurgaon
Inheritance is a well-established programming principle, and PHP makes use of this principle in its object model. This principle will affect the way many classes and objects relate to one another. For example, when you extend a class, the subclass inherits all of the public and protected methods from the parent class. Unless a class overrides those methods, they will retain their original functionality. This is useful for defining and abstracting functionality, and permits the implementation of additional functionality in similar objects without the need to reimplement all of the shared functionality. Example <?php class Foo { public function printItem($string) { echo 'Foo: ' . $string . PHP_EOL; } public function printPHP() { echo 'PHP is great.' . PHP_EOL; } } class Bar extends Foo { public function printItem($string) { echo 'Bar: ' . $string . PHP_EOL; } } $foo = new Foo(); $bar = new Bar(); $foo->printItem('baz'); // Output: 'Foo: baz' $foo->printPHP();       // Output: 'PHP is great' $bar->printItem('baz'); // Output: 'Bar: baz' $bar->printPHP();       // Output: 'PHP is great' ?>
Read More

Data Sending Ways in PHP

php-training-in-gurgaon
There are some certain ways to send your information or data to the PHP page- Using Form Methods - Get & Post Using Cookies & Session Using Query String / URL Rewriting Using Hidden form fieldForm MethodsThe GET Method: The GET method sends information separated by the ? Operator.Example: http://www.xyz.com/home.html?city=Gurgaon Please note that the GET method is restricted to send upto 1024 characters (1024 bytes) only. You should not use GET method if you have password or other confidential information to be proceeding over the server. GET can't be used to send binary data, like images or word documents, to the server. The PHP provides $_GET associative array or super global variable to access the data sent using GET method. The POST Method The POST method transfers information via HTTP…
Read More

PHP – Strings Functions

php-training-in-gurgaon
String functions are the most important functions frequently used in PHP. String is the sequence of characters, like "Let’s learn String functions”. There is no installation required to use string function. Example <?php $name = "Hirdesh Bhardwaj"; print($name); ?> String Concatenation Operator To concatenate two string variables together, we use the dot (.) operator − <?php $txt1="Hello Readers"; $txt2="8756"; echo $txt1 . " " . $txt2; ?> Using the strlen() function The strlen() function is used to get the length of a string. <?php $txt=”Webs Jyoti”; echo strlen($txt); ?> This will produce the following result – 10 (including space) Using the strpos() function The strpos() function is used to search for a text or character within a string. If the value is found then this will return the position of…
Read More

Working with Images – PHP

php-training-in-gurgaon
We need to create an HTML form that allows you to choose the file to be uploaded. Note: please make sure you have form method type is post and enctype=”mutipart/form-data” to to handle file uploading process successfully. HTML Code <form enctype="multipart/form-data" action="process.php" method="POST"> Choose File : <input name="myfile" type="file" /> <input type="submit" value="Upload" /> </form> Now create a PHP file process.php for handling file information <?php // get the uploaded file name $filename= $_FILES['myfile'][‘name’]; // get the file type $filetype= $_FILES['myfile'][‘type’]; // get the file size (in bytes) $filesize= $_FILES['myfile'][‘size’]; // You may put your validations here i.e restrict file size if($filesize>=1000000) { echo “ File is too Large, Maximum file size should be 1 MB”; exit; } // Validation to check if uploaded file is an Image if($filetype !=”image/jpeg”…
Read More

Sending email – Mail Function in PHP

php-training-in-gurgaon
Almost in every web application sending automated email by system is the common requirement. So, it’s very common and important part that must be known by developer. The simple example, when a visitor to your website fills out a enquiry form. mail function return a boolen value, return true if email sent successfully, false otherwise  Syntax: mail ($to , $subject , $message, $additional_headers); $to: This is the first parameter of mail function hold the email address of receiver, the address to which email has to be sent. $subject: Every email should have subject. This parameter cannot contain any newline characters. $message: This is the actual body or content of email to send.  Please note that every line should be break by \n and every line should not exceed the limit…
Read More

Require () and Include () function in PHP

php-training-in-gurgaon
The Include() and require() statements are used to insert codes written in other files, in the flow of  execution. The main of using include and require functions to integrate one page code or content into another page. You can maintain usually some repeated functionality in the form of PHP file and finally you can call it wherever you want. See, the following example demonstrates how to integrate a menu content in other pages of PHP. There is a page in menu.php and it can be included in some other pages of the website. Menu.php <a href=”index.php”>Home</a> <a href=”services.php”>Services</a> <a href=”about.php”>About Us</a> <a href=”contact.php”>Contact Us</a> The following page index.php uses above menu.php content. See the below code how it follows <head> <title>My Web page</title> </head> <body> <?php include  “menu.php “; ?> </body> Difference between Include…
Read More

Data types in Mysql / Mariadb

php-training-in-gurgaon
Numeric Data Types: INT (Integer): Int data type represents an integer of normal size. So simply it can used to store numeric value. There are also BIGINT, MEDIUMINT, SMALLINT and TINYINT which represent different range of integer values. DECIMAL: Decimal data type represents numbers with specific floating values. Maximum permitted value is 65 and maximum decimals are 30. There are also FLOAT and DOUBLE to store numeric values with floating point. BOOLEAN:  This data type associates a value 0 with ―”false”, and a value 1 with true. Date and Time Data Types:  DATE: The DATE data type represents a date in “YYYY-MM-DD” format. TIME: The TIME data type represents a time in "HH:MM:SS" format. DATETIME: The DATETIME data type represents date and time in “YYYY-MM-DD HH:MM:SS” format. TIMESTAMP: This data…
Read More

The do-while loop

php-training-in-gurgaon
Difference Between while and do…while Loop: With a while loop, the condition to be evaluated is tested at the beginning of each loop statement, so if the conditional expression evaluates to false, the loop will never be executed. With a do-while loop, on the other hand, the loop will always be executed once, even if the conditional expression is false, because the condition is evaluated at the end of the loop statement. Example: <?php $i = 1; do { $i++; echo  $i . "<br>"; } while($i <= 3); ?>  Output: 2 3 4
Read More