PHP Archive
Note : In this assignment, I am taking the same database (mydb) that we was created in Day9, but create below new tables for this assignment and add some records in all three table i.e. tbcity, tbcourse and tbstudent. create table tbcity (id int primary key auto_increment, name varchar(50)) create table tbcourse(id int primary key
We have done database connectivity in Day 9, now we will manipulate data in database (i.e. insert, edit, update and delete) with PHP. To manipulate the data I have created more than 1 PHP files, So take a separate folder (I am taking Day11) to put all those below mentioned files. Note : In this
This is one of the strong feature of PHP that we can include content of one PHP or HTML file into another PHP file. With this feature we can reduce our codes of line and also avoid repentance of code. This can be done With the help of: include() function require() function include_once() function require_once()
Database is used to store information. In PHP we are using MySql as database server. Below are the steps to use MySql server with PHP: Step 1 : Start MySql from your xampp panel. Step 2 : Open “http://localhost/phpmyadmin/” in browser. Step 3 : Create new database in your localhost server (let’s take database name
Form validations are used to filter valid data from form. Below are the examples of form validation with regular expression. These are also called server side validations. Program 29: Required field validation. <?php $msg = “”; if(isset($_REQUEST[‘btnSubmit’])) { $name = trim($_REQUEST[‘txtName’]); $email = trim($_REQUEST[‘txtEmail’]); $mobile = trim($_REQUEST[‘txtMobile’]); $message = trim($_REQUEST[‘txtMessage’]); if($name==””) { $msg = $msg
Form is one of the powerful features of PHP. Below is an example of HTML Form: Program 25: Form example with GET method. <?php echo “hello “.$_GET[‘txtName’]; ?> <html> <body> <form> Name: <input type=”text” name=” txtName”> <br> <input type=”submit”> </form> </body> </html> Note: By default form has get method, so $_GET is use in above
Array can hold more than one value at a time. It’s a organized collection of key-value pairs. By default keys of array starts with 0, whoever we can define our own keys also. Syntax: $Ar = Array(emement1, emement2, emement3,…); Program 21: Define and display indexed array. <?php $ar = Array(30,56,amit,ravi); for($i=0; $i < count($ar); $i++)
Loop is use to do repetitive work until task has not been completed. 1) Understanding “while” Control Structure while is the simplest type of loop in PHP, statement inside the while loop executes until condition in ture. Syntax: while (condition) { statement here will execute when condition is true. } Program 13: Display series 1-10.
Comment code is a line that is not executed as a part of the program. It’s only readable by someone who is editing the code! Comments are useful for Documentation to let other members of your team understand what you were doing in your code. PHP supports three ways of commenting: <?php // This is
Variable: variable is name of place where computer holds the value temporarily in computer’s memory (RAM), that we can use in our program. In PHP variable is defined with “$” sign. In below program “$a” is a variable contain an integer value “23”, “$b” contain string value “Albert” and $c contain float value “232.44”. Program