img

How to create website using PHP MYSQL?

The most important requirement to use PHP applications are as follow : -

Install wampserver2.5-Apache-2.49-Mysql-5.6 or other software
Download

Install vcredist_x86.exe
Download

Install jdk-8u40-windows-i586.exe
Download

After you install the server, you can find wamp folder in C: drive and you need to have your all files inside the www folder that www folder is available inside the wamp folder at your C: drive. Instead of saving the files in .html extention now you need to save the files with .php extention. To execute those files, first you need to run the wampserver-Apache, wait untill the color of the wampser icon turns to green from red and yellow, then type localhost in your google crome browser and put a slash / and type the folder name where you have kept your files, again put slash / and then type the name of the php file which you want to call. example : - localhost/xyzfoldername/index.php

We need to upload data to the database server, so we can easily do that by using PHP variables and tags. Using PHP and Mysql we can upload and download data both in local server and web server.

Sometimes in our web application we need to transfer data from one webpage to other webpage then we can use PHP tag and PHP variables to do that easily.

Many times we have to use a common set of programs or coding in multiple HTML files and we often need to change the coding. Therefore we have to make the same changes in all HTML files and it takes lots of time and effort. But if we use a PHP file and write those common set of program or coding in a single PHP files and include that PHP files in all HTML pages, where we have to use that set of programs. So while we need to change something then we just have to change the PHP file's coding and that changes will automatically effect in all those HTML pages.

PHP is a widely used open source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

What is PHP :- PHP is also called Hypertext Preprocessor and PHP is defined as an HTML embedded scripting language that is used to create web pages.

Why is PHP called a hypertext preprocessor :- PHP is called Hypertext Preprocessor because its libraries are already compiled.when any person request for any PHP page in the address bar of the browser that request is first sent to the server then server interpret PHP files and return back response in form of Html.

What is the technology of PHP :- PHP is an alternative to Microsoft's Active Server Page technology. As with ASP, the PHP script is embedded within a Web page along with its HTML. Before the page is sent to a user that has requested it, the Web server calls PHP to interpret and perform the operations called for in the PHP script.

What is Meant by PHP :- PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

What is the difference between PHP and HTML :- The Difference Between HTML and PHP is the colors, fonts and styles of this entire website are driven by (CSS and HTML) of web pages. HTML allows you to put images, text, videos, forms and other pieces of content together into a cohesive webpage in client side browser where as PHP deal with the data and server files.

What is PHP and what does it do :- PHP is mainly focused on server side scripting, so you can collect data report, generate dynamic page content or send and receive cookies and much more.

PHP Tutorial for Beginners Step by Step

See the PHP example bellow, how to accept user input

Save this file as test.php in www folder and execute by typing localhost/test.php from your browser

<html>
<head>
<title>Test</title>
</head>
<body>
<center>
<form action="test.php" method="post" enctype="multipart/form-data">
<center><h4><b>Registration Form</b></h4></center>
<div>
<label>Photo: </label>
<input type="file" required="required" name="photo">
</div>
<br>
<div>
<label>Name: </label>
<input type="text" placeholder="Enter your Name" required="required" name="name">
</div>
<br>
<div>
<label>Age: </label>
<input type="number" placeholder="Enter Your Age" required="required" name="age">
</div>
<br>
<div>
<label>Class: </label>
<input type="number" placeholder="Enter Your Class" required="required" name="class">
</div>
<br>
<div>
<label>Marks: </label>
<input type="number" placeholder="Enter Your Marks" required="required" name="marks">
</div>
<br>
<div>
<input type="submit">
</div>
<br>
</form>
</center>
<?php
echo '<div style="display:none;">';
$target_file = basename($_FILES["photo"]["name"]);
move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file);
$photo = $target_file;
$name = $_POST["name"];
$age = $_POST["age"];
$class = $_POST["class"];
$marks = $_POST["marks"];
echo '</div>';
echo '<center><img style="width:100px;" src="' . $photo . '" alt="img"></center>';
echo '<center><h3>My-self ' . $name . '</h3></center>';
echo '<center><h3>I am ' . $age . ' years old</h3></center>';
echo '<center><h3>I read in class ' . $class . '</h3></center>';
echo '<center><h3>I have scored ' . $marks . ' marks</h3></center>';
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP While Loop
See the example bellow :-
The application will accept value from user and this will return the counter value on submit
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="margin-top:200px; background-color:pink; width:400px; padding:20px;">
<center><h3>PHP While Loop</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px; line-height:24px;" name="text" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Initial Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="a" type="number" placeholder="Put value" required="required">
<br><br>
<label style="margin-right:20px"><b>Last Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="b" type="number" placeholder="Put value" required="required">
<br><br>
<label style="margin-right:20px"><b>Counter Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="c" type="number" placeholder="Put value" required="required">
<br><br>
<label style="margin-right:20px"><b>Table Of</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="table" type="number" placeholder="Put value" required="required">
<br><br>
<input style="height:24px; padding-left:20px; padding-right:20px;" type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none">';
$text = $_POST["text"];
$a = (int)$_POST["a"];
$b = (int)$_POST["b"];
$c = (int)$_POST["c"];
$table = (int)$_POST["table"];
echo '</div>';
if ($a < $b)
{
while($a<$b)
{
echo "<center><h5><span style='border-radius:20px 0px 0px 20px; background-color:green; padding:6px; color:#ffffff;'>" . "Hello </span><span style='background-color:#0033ff; padding:6px; color:#ffffff;'>" . $text . "</span><span style='background-color:orange; padding:6px; color:#ffffff;'> this is counter number </span><span style='background-color:red; padding:6px; color:#ffffff;'>" . $a . "</span><span style='border-radius:0px 20px 20px 0px; background-color:blue; padding:6px; color:#ffffff;'> and (" . $a . " x " . $table . " = " . $a * $table . ")</span></h5></center>";
$a=$a+$c;
}
}
else
{
while($a>$b)
{
echo "<center><h5><span style='border-radius:20px 0px 0px 20px; background-color:green; padding:6px; color:#ffffff;'>" . "Hello </span><span style='background-color:#0033ff; padding:6px; color:#ffffff;'>" . $text . "</span><span style='background-color:orange; padding:6px; color:#ffffff;'> this is counter number </span><span style='background-color:red; padding:6px; color:#ffffff;'>" . $a . "</span><span style='border-radius:0px 20px 20px 0px; background-color:blue; padding:6px; color:#ffffff;'> and (" . $a . " x " . $table . " = " . $a * $table . ")</span></h5></center>";
$a=$a-$c;
}
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP FOR Loop
See the example bellow :-
The application will accept value from user and this will return the counter value on submit
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="margin-top:200px; background-color:pink; width:400px; padding:20px;">
<center><h3>PHP For Loop</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px; line-height:24px;" name="text" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Initial Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="a" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Last Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="b" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Counter Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="c" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Table Of</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="table" type="number" required="required">
<br><br>
<input style="height:32px; padding-left:20px; padding-right:20px;" type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none">';
$text = $_POST["text"];
$a = (int)$_POST["a"];
$b = (int)$_POST["b"];
$c = (int)$_POST["c"];
$table = (int)$_POST["table"];
echo '</div>';
if ($a < $b)
{
for($i = $a; $i<$b; $i=$i+$c)
{
echo "<center><h5><span style='border-radius:20px 0px 0px 20px; background-color:green; padding:6px; color:#ffffff;'>" . "Hello </span><span style='background-color:#0033ff; padding:6px; color:#ffffff;'>" . $text . "</span><span style='background-color:orange; padding:6px; color:#ffffff;'> this is counter number </span><span style='background-color:red; padding:6px; color:#ffffff;'>" . $i . "</span><span style='border-radius:0px 20px 20px 0px; background-color:blue; padding:6px; color:#ffffff;'> and (" . $i . " x " . $table . " = " . $i * $table . ")</span><h5><center>";
}
}
else
{
for($i = $a; $i>$b; $i=$i-$c)
{
echo "<center><h5><span style='border-radius:20px 0px 0px 20px; background-color:green; padding:6px; color:#ffffff;'>" . "Hello </span><span style='background-color:#0033ff; padding:6px; color:#ffffff;'>" . $text . "</span><span style='background-color:orange; padding:6px; color:#ffffff;'> this is counter number </span><span style='background-color:red; padding:6px; color:#ffffff;'>" . $i . "</span><span style='border-radius:0px 20px 20px 0px; background-color:blue; padding:6px; color:#ffffff;'> and (" . $i . " x " . $table . " = " . $i * $table . ")</span><h5><center>";
}
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP For Loop Table
See the example bellow :-
The application will accept value from user and this will return the counter value on submit
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="margin-top:200px; background-color:pink; width:400px; padding:20px;">
<center><h3>PHP For Loop Table</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px; line-height:24px;" name="text" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Initial Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="a" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Last Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="b" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Counter Value</b></label>
<input style="width:60px; padding-left:20px; line-height:24px;" name="c" type="number" required="required">
<br><br>
<input style="height:32px; padding-left:20px; padding-right:20px;" type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none">';
$text = $_POST["text"];
$a = (int)$_POST["a"];
$b = (int)$_POST["b"];
$c = (int)$_POST["c"];
echo '</div>';
if ($a < $b)
{
echo '<center>';
echo '<table>';
for($i = $a; $i<$b; $i=$i+$c)
{
echo '<tr>';
for($ii = $a; $ii<$b; $ii=$ii+$c)
{
echo '<td style="background-color:green; padding:6px; color:#ffffff;">' . $text . '</td><td style="background-color:blue; padding:6px; color:#ffffff;">Row '.$i.'</td><td style="background-color:red; padding:6px; color:#ffffff;">Colom '.$ii.'</td>';
}
echo '</tr>';
}
echo '</table>';
echo '</center>';
}
else
{
echo '<center>';
echo '<table>';
for($i = $a; $i>$b; $i=$i-$c)
{
echo '<tr>';
for($ii = $a; $ii>$b; $ii=$ii-$c)
{
echo '<td style="background-color:green; padding:6px; color:#ffffff;">' . $text . '</td><td style="background-color:blue; padding:6px; color:#ffffff;">Row '.$i.'</td><td style="background-color:red; padding:6px; color:#ffffff;">Colom '.$ii.'</td>';
}
echo '</tr>';
}
echo '</table>';
echo '</center>';
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Reverse Calculation
See the example bellow :-
The application will accept value from user and this will return the reverse value on submit
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="margin-top:200px; background-color:pink; width:400px; padding:20px;">
<center><h3>PHP Reverse Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px; line-height:32px;" name="text" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Value</b></label>
<input style="padding-left:20px; line-height:32px;" name="a" type="number" placeholder="Enter value" required="required">
<br><br>
<input style="height:32px; padding-left:20px; padding-right:20px;" type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none">';
$text = $_POST["text"];
$a = (int)$_POST["a"];
$rev =0;
echo '</div>';
echo '<center><h3 style="width:300px; border-radius:20px; background-color:orange; padding:6px; color:#ffffff;">Original Number is ' . $a . '</h3></center>';
while ($a != 0)
{
$d = $a%10;
$rev = ($rev*10)+$d;
$a = (int)($a/10);
echo '<center><h3 style="width:300px; border-radius:20px; background-color:green; padding:6px; color:#ffffff;">The reverse value is ' . $rev . '</h3></center>';
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Switch Case Break
See the example bellow :-
The application will accept string value from user and will do calculation according to the user queries on submit
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body
{
background-color: #ff99cc;
}
div
{
width:300px;
margin-top:100px;
padding:20px;
background-color: #ffffff;
}
select
{
width:40px;
height:32px;
}
#c
{
width:100px;
height:32px;
}
#text
{
padding-left:20px;
height:32px;
}
input
{
padding-left:10px;
padding-right:10px;
height:32px;
}
</style>
</head>
<body>
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div>
<center><h3>PHP Application</h3></center>
<label><b>Enter Name</b></label>
<input name="text" type="text" placeholder="Enter your Name" required="required">
<br><br>
<select name="a">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<select name="b">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<select id="c" name="c">
<option>Addition</option>
<option>Subtraction</option>
<option>Multiplication</option>
<option>Division</option>
<option>Verify (>)NO</option>
<option>Divisible</option>
<option>Between (10-20)</option>
</select>
<center><h5 id="d">Message</h5></center>
<center><h5 id="show">0%</h5></center>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$text = $_POST["text"];
$a = (int)$_POST["a"];
$b = (int)$_POST["b"];
$ab = $a + $b;
$c = $_POST["c"];
echo '</div>';
switch($c)
{
case "Addition":
echo '<center><h4 style="width:300px; line-height:24px; padding:6px; background-color:#ffffff; border-radius:0px 0px 20px 20px;">';
echo "The sum of two numbers is " . $ab;
echo '</h4></center>';
break;
case "Subtraction":
echo '<center><h4 style="width:300px; line-height:24px; padding:6px; background-color:#ffffff; border-radius:0px 0px 20px 20px;">';
echo "The substraction of two numbers is " . ($a - $b);
echo '</h4></center>';
break;
case "Multiplication":
echo '<center><h4 style="width:300px; line-height:24px; padding:6px; background-color:#ffffff; border-radius:0px 0px 20px 20px;">';
echo "The multiplication of two numbers is " . $a * $b;
echo '</h4></center>';
break;
case 'Division':
echo '<center><h4 style="width:300px; line-height:24px; padding:6px; background-color:#ffffff; border-radius:0px 0px 20px 20px;">';
echo "The division of two numbers is " . (int)($a / $b);
echo '</h4></center>';
break;
case 'Verify (>)NO':
echo '<center><h4 style="width:300px; line-height:24px; padding:6px;">';
$z = (($a > $b)? ("Hello " . $text . " your first number " . $a . " is greater than your second number " . $b):("Hello " . $text . " your second number " . $b . " is greater than your first number " . $a));
echo $z;
echo '</h4></center>';
break;
case 'Divisible':
echo '<center><h4 style="width:300px; line-height:24px; padding:6px;">';
$z = ((($a % $b)==0)? ("Hello " . $text . " your first number " . $a . " is divisible by your second number " . $b):("Hello " . $text . " your first number " . $b . " is not divisible by your second number " . $a));
echo $z;
echo '</h4></center>';
break;
case 'Between (10-20)':
echo '<center><h4 style="width:300px; line-height:24px; padding:6px;">';
$z = (($ab >= 10 && $ab <=20)? ("Hello " . $text . " the sum of your two numbers " . $ab . " is between 10 and 20"):("Hello " . $text . " the sum of your two numbers " . $ab . " is not between 10 and 20"));
echo $z;
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Include File
See the example bellow :-
The application will use the include method during several conditions on submit
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
See bellow after this application there are two other applications, save it as include.php and include2.php in same folder
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="margin-top:200px; background-color:pink; width:400px; padding:20px;">
<center><h3>PHP Sing Up</h3></center>
<label style="margin-right:20px"><b>Username</b></label>
<input style="padding-left:20px; line-height:24px;" name="username" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Password</b></label>
<input style="padding-left:20px; line-height:24px;" name="password" type="password" placeholder="Enter Password" required="required">
<br><br>
<label style="margin-right:20px"><b>Confirm Password</b></label>
<input style="padding-left:20px; line-height:24px;" name="confirm" type="password" placeholder="Confirm Password" required="required">
<br><br>
<input style="height:32px; padding-left:20px; padding-right:20px;" type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none">';
$username = $_POST["username"];
$password = $_POST["password"];
$confirm = $_POST["confirm"];
echo '</div>';
if ($password == "" && $confirm == "")
{}
elseif ($password != $confirm)
{
include('include2.php');
}
else
{
include('include.php');
}
?>
</body>
</html>
Save this file as include.php in same folder
<?php
$username = $_POST["username"];
$password = $_POST["password"];
echo '<center>'
. '<div>'
. '<h4>Your username is '.$username.'</h4>'
. '<h4>and your password is '.$password.'</h4>'
. '</div>'
. '</center>';
?>
Save this file as include2.php in same folder
<?php
$username = $_POST["username"];
$password = $_POST["password"];
echo '<center>'
. '<div>'
. '<h4>Sorry '.$username.'</h4>'
. '<h4>Your password '.$password.' is invalid</h4>'
. '</div>'
. '</center>';
?>
Show

PHP Tutorial for Beginners Full

PHP Array in For Loop
See the example bellow :-
The program will retrieve data in array format
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="get" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Array Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your State</b></label>
<input style="padding-left:20px" name="text[]" type="text" placeholder="Enter Your State" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your District</b></label>
<input style="padding-left:20px" name="text[]" type="text" placeholder="Enter Your District" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your City</b></label>
<input style="padding-left:20px" name="text[]" type="text" placeholder="Enter Your City" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your Pincode</b></label>
<input style="padding-left:20px; width:120px;" name="text[]" type="number" required="required">
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
if( isset($_GET['name'] ) && ($_GET['text'] ) && is_array($_GET['text']) )
{
$name = $_GET['name'];
$text = $_GET['text'];
for ($i = 0; $i < 4; $i++)
{
echo "<center><h4 style='width:400px; line-height:24px; background-color:pink; border-radius:20px; border:2px solid red;'>Hello " . $name . " you stay at ". $text[$i] . "</h4></center>";
}
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Explode in Foreach Loop
See the example bellow :-
The program will retrieve data in single 'address' string and seperate that to array format
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="get" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Explode Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your Address</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter Your Full Address" required="required">
<br><br>
<label style="margin-right:20px"><b>Separate by Delimeter</b></label>
<input style="width:60px; padding-left:20px" name="text2" type="text" required="required">
<br><br>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
if( isset($_GET['name'] ) && ($_GET['text'] ) && ($_GET['text2'] ) )
{
$name = $_GET['name'];
$text = $_GET['text'];
$text2 = $_GET['text2'];
$v = explode($text2, $text);
foreach ($v as $tmp )
{
echo "<center><span style='width:400px; padding:6px; background-color:red; color:#ffffff; border-radius:20px 0px 0px 20px'>Hello " . $name . "</span><span style='width:400px; padding:6px; background-color:blue; color:#ffffff; border-radius:0px 20px 20px 0px;'> you stay at ". $tmp . "</span></center><br>";
}
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Implode in Array
See the example bellow :-
The program will retrieve data from separate string and hold that in array format
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="get" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Implode Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your State</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter Your State" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your District</b></label>
<input style="padding-left:20px" name="text2" type="text" placeholder="Enter Your District" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your City</b></label>
<input style="padding-left:20px" name="text3" type="text" placeholder="Enter Your City" required="required">
<br><br>
<label style="margin-right:20px"><b>Enter Your Pincode</b></label>
<input style="padding-left:20px; width:120px;" name="text4" type="number" required="required">
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
if( isset($_GET['name'] ) && ($_GET['text'] ) && ($_GET['text2'] ) && ($_GET['text3'] ) && ($_GET['text4'] ) )
{
$name = $_GET['name'];
$text = $_GET['text'];
$text2 = $_GET['text2'];
$text3 = $_GET['text3'];
$text4 = $_GET['text4'];
$array = array($text4, $text3, $text2, $text);
echo "<center><span style='color:#ffffff; background-color:green; padding:6px; border-radius:20px 0px 0px 20px;'>Hello " . $name . "</span><span style='color:#ffffff; background-color:blue; padding:6px; border-radius:0px 20px 20px 0px;'> your address is " . implode(", ",$array) . "</span></center>";
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Whole Number Calculation
See the example bellow :-
The program will convert a negative number into a whole number
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="get" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Whole Number Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Negative Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="number" required="required">
<center><h5>Calculation of Hole Number</h5></center>
<select><option>Hole Number</option></select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
if( isset($_GET['name'] ) )
{
$name = $_GET['name'];
}
if( isset($_GET['text'] ) )
{
$text = $_GET['text'];
echo '<center><h4>';
echo "Hello " . $name . " the hole number of your number is " . abs($text);
echo '</h4></center>';
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Square Root Calculation
See the example bellow :-
The program will accept number and return its square root value
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="get" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Square Root Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Provide Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="number" required="required">
<center><h5>Square Root Calculation</h5></center>
<select style="width:140px; margin-right:20px;"><option>Square Root</option></select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
if( isset($_GET['name'] ) )
{
$name = $_GET['name'];
}
if( isset($_GET['text'] ) )
{
$text = $_GET['text'];
echo '<center><h4>';
echo "Hello " . $name . " the square root of your number is " . sqrt($text);
echo '</h4></center>';
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Number Identification
See the example bellow :-
The program will accept three numbers and then it will identify and return the maximum number
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Identify Value Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Number</b></label>
<input style="padding:6px; width:60px;" name="text2" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Number</b></label>
<input style="padding:6px; width:60px;" name="text3" type="number" required="required">
<center><h5>Math Calculation</h5></center>
<select style="width:140px; margin-right:20px;" name="operation">
<option>Maximum Number</option>
<option>Minimum Number</option>
</select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$text3 = $_POST["text3"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'Maximum Number':
echo '<center><h4>';
echo "Hello " . $name . " the maximum of three numbers is " . max($text, $text2, $text3);
echo '</h4></center>';
break;
case 'Minimum Number':
echo '<center><h4>';
echo "Hello " . $name . " the minimum of three numbers is " . min($text, $text2, $text3);
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Power Calculation
See the example bellow :-
The program will accept number and then it will calculate the power value of that number
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Power Calculation Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Power Value</b></label>
<input style="padding:6px; width:60px;" name="text2" type="number" required="required">
<center><h5>Math Calculation</h5></center>
<select style="width:140px; margin-right:20px;" name="operation"><option>Power</option></select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'Power':
echo '<center><h4>';
echo "Hello " . $name . " the power of your number " . $text . " and power " . $text2 . " is " . pow($text, $text2);
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP RoundUp from Decimal
See the example bellow :-
The program will accept decimal number and then it will round up the number to its nearest value
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP RoundUp Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Decimal Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="text" required="required">
<br><br>
<label style="margin-right:20px"><b>Decimal Place</b></label>
<input style="padding:6px; width:60px;" name="text2" type="number" required="required">
<center><h5>Rounded Decimal Value</h5></center>
<select style="width:140px; margin-right:20px;" name="operation"><option>Decimal</option></select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'Decimal':
echo '<center><h4>';
echo "Hello " . $name . " the rounded figure of your number " . $text . " of " . $text2 . " place is " . round($text, $text2);
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Ceil value from Decimal
See the example bellow :-
The program will accept decimal number and then it will return the nearest and highest value at the last decimal figure
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Ceil Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Decimal Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="text" required="required">
<center><h5>Highest Decimal Value</h5></center>
<select style="width:140px; margin-right:20px;" name="operation"><option>Decimal</option></select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'Decimal':
echo '<center><h4>';
echo "Hello " . $name . " the highest decimal figure of your number " . $text . " is " . ceil($text);
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Floor value from Decimal
See the example bellow :-
The program will accept decimal number and then it will return the nearest and lowest value at the last decimal figure
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Floor Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write a Decimal Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="text" required="required">
<center><h5>Lowest Decimal Value</h5></center>
<select style="width:140px; margin-right:20px;" name="operation"><option>Decimal</option></select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'Decimal':
echo '<center><h4>';
echo "Hello " . $name . " the lowest decimal figure of your number " . $text . " is " . floor($text);
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP While Loop with Factor
See the example bellow :-
The program will accept value and run a While Loop and it will return factor value of the number inside the loop unless the condition is false
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="get" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Factor and While Loop Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Initial Number</b></label>
<input style="padding:6px; width:60px;" name="text" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>End Number</b></label>
<input style="padding:6px; width:60px;" name="text2" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Factories Place</b></label>
<input style="padding:6px; width:60px;" name="text3" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Counter Number</b></label>
<input style="padding:6px; width:60px;" name="text4" type="number" required="required">
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
if( isset($_GET['name'] ) && ($_GET['text'] ) && ($_GET['text2'] ) && ($_GET['text3'] ) && ($_GET['text4'] ) )
{
$name = $_GET['name'];
$text = $_GET['text'];
$text2 = $_GET['text2'];
$text3 = $_GET['text3'];
$text4 = $_GET['text4'];
$f = $text3;
$n = $text;
if ($text>$text2)
{
while ($n>$text2)
{
$f = $f*$n;
$n = $n - $text4;
echo "<center><span style='background-color:green; padding:6px; border-radius:20px 0px 0px 20px;'>Hello " . $name . " your number is " . $n . "</span><span style='background-color:red; padding:6px; border-radius:0px 20px 20px 0px;'> and the factor is " . $f . "</span></center><br>";
}
}
else
{
while ($n<$text2)
{
$f = $f*$n;
$n = $n + $text4;
echo "<center><span style='background-color:green; padding:6px; border-radius:20px 0px 0px 20px;'>Hello " . $name . " your number is " . $n . "</span><span style='background-color:red; padding:6px; border-radius:0px 20px 20px 0px;'> and the factor is " . $f . "</span></center><br>";
}
}
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Text Converter
See the example bellow :-
The program will accept value from the user and then it will convert the value according to the selected condition
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Text Converter Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Write Text</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter some Text" required="required">
<center><h5>Text Converter</h5></center>
<select style="width:140px; margin-right:20px;" name="operation">
<option>Upper-Case</option>
<option>Lower-Case</option>
<option>Left-Space-Remove</option>
<option>Right-Space-Remove</option>
<option>Space-Remove</option>
<option>Text-Length</option>
<option>Text-Reverse</option>
<option>Count-Word</option>
</select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'Upper-Case':
echo '<center><h4>';
echo "Hello " . $name . " your text is converted to uppercase " . strtoupper($text);
echo '</h4></center>';
break;
case 'Lower-Case':
echo '<center><h4>';
echo "Hello " . $name . " your text is converted to lowercase " . strtolower($text);
echo '</h4></center>';
break;
case 'Left-Space-Remove':
echo '<center><h4>';
echo "Hello " . $name . " left space is removed from your text (" . ltrim($text) . ")";
echo '</h4></center>';
break;
case 'Right-Space-Remove':
echo '<center><h4>';
echo "Hello " . $name . " right space is removed from your text (" . rtrim($text) . ")";
echo '</h4></center>';
break;
case 'Space-Remove':
echo '<center><h4>';
echo "Hello " . $name . " both left and right space is removed from your text (" . trim($text) . ")";
echo '</h4></center>';
break;
case 'Text-Length':
echo '<center><h4>';
echo "Hello " . $name . " the lenght of your text is " . strlen($text);
echo '</h4></center>';
break;
case 'Text-Reverse':
echo '<center><h4>';
echo "Hello " . $name . " your text is reversed as " . strrev($text);
echo '</h4></center>';
break;
case 'Count-Word':
echo '<center><h4>';
echo "Hello " . $name . " you have written " . str_word_count($text) . " words";
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Text Cutter
See the example bellow :-
The program will accept value from the user and then it will cut the string as per request
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP Text Cutter Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Full Text</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter full text" required="required">
<br><br>
<label style="margin-right:20px"><b>Starting Character</b></label>
<input style="padding:10px; width:60px;" name="text2" type="number" required="required">
<br><br>
<label style="margin-right:20px"><b>Character Count</b></label>
<input style="padding:10px; width:60px;" name="text3" type="number" required="required">
<br><br>
<center><input style="padding:10px; border-radius:20px; background-color:#999999; border:none;" readonly value="Cutter SUBSTR METHOD"></center>
<br>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$text3 = $_POST["text3"];
echo '</div>';
echo '<center><h4>';
echo $name . " " . substr($text, $text2, $text3);
echo '</h4></center>';
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Text Replacer
See the example bellow :-
The program will accept string value from the user and then it will replace the string from the position requested by the user
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP String Replacer Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Full Text</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter full text" required="required">
<br><br>
<label style="margin-right:20px"><b>Replace With</b></label>
<input style="padding-left:20px" name="text2" type="text" placeholder="Enter specific text" required="required">
<br><br>
<label style="margin-right:20px"><b>Character Position After</b></label>
<input style="padding:10px; width:60px;" name="text3" type="number" required="required">
<br><br>
<center><input style="padding:10px; border-radius:20px; background-color:#999999; border:none;" readonly value="Cutter SUBSTR_REPLACE"></center>
<br>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$text3 = $_POST["text3"];
echo '</div>';
echo '<center><h4>';
echo $name . " " . substr_replace($text, $text2, $text3);
echo '</h4></center>';
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

See the example bellow :-
The program will accept string value from the user and then it will replace the exact string requested by the user
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP String Replacer 2nd Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Full Text</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter full text" required="required">
<br><br>
<label style="margin-right:20px"><b>Replace With</b></label>
<input style="padding-left:20px; width:100px;" name="text2" type="text" required="required">
<br><br>
<label style="margin-right:20px"><b>Find Text</b></label>
<input style="padding-left:20px; width:100px;" name="text3" type="text" required="required">
<br><br>
<center><input style="padding:10px; border-radius:20px; background-color:#999999; border:none;" readonly value="Cutter STR_REPLACE"></center>
<br>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$text3 = $_POST["text3"];
echo '</div>';
echo '<center><h4>';
echo $name . " " . str_replace($text3, $text2, $text);
echo '</h4></center>';
?>
</body>
</html>
Show

PHP Tutorial for Beginners Step by Step

PHP Text Finder
See the example bellow :-
The program will accept string value from the user and then it will search the exact string if present in the input value
Save the file in your www folder as class.php and execute the application by typing localhost/class.php from your browser
<html>
<head>
<title>Basic Learner for Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#ff99cc">
<form action="class.php" method="post" enctype="multipart/form-data">
<center>
<div style="width:400px; margin-top:100px; padding:20px; background-color:#ffffff;">
<center><h3>PHP String Finder Application</h3></center>
<label style="margin-right:20px"><b>Enter Name</b></label>
<input style="padding-left:20px" name="name" type="text" placeholder="Enter your Name" required="required">
<br><br>
<label style="margin-right:20px"><b>Full Text</b></label>
<input style="padding-left:20px" name="text" type="text" placeholder="Enter full text" required="required">
<br><br>
<label style="margin-right:20px"><b>Specific Text</b></label>
<input style="padding-left:20px" name="text2" type="text" placeholder="Enter specific text" required="required">
<center><h5>Search Text</h5></center>
<select style="width:140px; margin-right:20px;" name="operation">
<option>STRSTR METHOD</option>
<option>STRCHR METHOD</option>
</select>
<input type="submit" value="Action">
</div>
</center>
</form>
<?php
echo '<div style="display:none;">';
$name = $_POST["name"];
$text = $_POST["text"];
$text2 = $_POST["text2"];
$operation = $_POST["operation"];
echo '</div>';
switch($operation)
{
case 'STRSTR METHOD':
echo '<center><h4>';
echo "<span style='padding:6px; background-color:skyblue; border-radius:20px 0px 0px 20px;'>" . $name . " </span><span style='padding:6px; background-color:aqua; border-radius:0px 20px 20px 0px;'> " . strstr($text, $text2) . "</span>";
echo '</h4></center>';
break;
case 'STRCHR METHOD':
echo '<center><h4>';
echo "<span style='padding:6px; background-color:skyblue; border-radius:20px 0px 0px 20px;'>" . $name . " </span><span style='padding:6px; background-color:aqua; border-radius:0px 20px 20px 0px;'> " . strchr($text, $text2) . "</span>";
echo '</h4></center>';
break;
}
?>
</body>
</html>
Show

PHP Tutorial for Beginners Full

PHP Class and Object Method
See the example bellow :-
The program will calculate the payable income tax according to the tax slab of 2017
Save the file in your www folder as tax.php and execute the application by typing localhost/class.php from your browser
<html>
<head><title>Test</title></head>
<body style="background-color:pink">
<center>
<div style="margin-top:20px; background-color:#ffffff; width:500px; padding:10px;">
<form method="get" action="tax.php" name="form">
<center><h3>Calculate your payable annual TAX</h3></center>
<label style="font-family:myfont; margin-right:20px;">Enter your Name</label>
<input style="border-radius:4px; border:1px solid #333333; padding-left:20px; line-height:24px;" type="text" placeholder="Enter your name" required="required" name="name"><br><br>
<label style="font-family:myfont; margin-right:20px;">Enter your Salary</label>
<input style="border-radius:4px; border:1px solid #333333; padding-left:20px; line-height:24px; width:100px;" type="number" required="required" name="income"><br><br>
<input type="submit" value="Calculate">
</form>
</div>
</center>
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
class ABC
{
private function first($x1)
{
$x = $x1-250000;
$y = $x*(5/100);
return $y;
}
private function second($x1)
{
$x = $x1-500000;
$y = ($x*(20/100))+12500;
return $y;
}
private function third($x1)
{
$x = $x1-1000000;
$y = ($x*(30/100))+12500+100000;
return $y;
}
private function a ($x, $x1)
{
echo "<center><h4 style='width:500px; padding:4px; border-radius:20px; border:2px solid green; color:green'>Hello " . $x . " your annual payable tax is rupees " . $this->first($x1) . "</h4></center>";
}
private function b ($x, $x1)
{
echo "<center><h4 style='width:500px; padding:4px; border-radius:20px; border:2px solid green; color:green'>Hello " . $x . " your annual payable tax is rupees " . $this->second($x1) . "</h4></center>";
}
private function c ($x, $x1)
{
echo "<center><h4 style='width:500px; padding:4px; border-radius:20px; border:2px solid green; color:green'>Hello " . $x . " your annual payable tax is rupees " . $this->third($x1) . "</h4></center>";
}
public function month ($x11, $x12)
{
$xx = $x12*12;
if ($xx>250000 && $xx<500000)
{
$this->a($x11, $xx);
}
elseif ($xx>500000 && $xx<1000000)
{
$this->b($x11, $xx);
}
elseif ($xx>1000000)
{
$this->c($x11, $xx);
}
else
{
echo "<center><h4 style='width:500px; padding:4px; border-radius:20px; border:2px solid green; color:green'>Hello " . $x11 . " your annual income is not taxable</h4></center>";
}
}
}
if( isset($_GET['name']) && isset($_GET['income']))
{
$name = $_GET['name'];
$income = $_GET['income'];
$salary = (int)$_GET['income'];
$o5 = new ABC();
$o5->month($name, $salary);
}
?>
</body>
</html>
Show

How to use PHP, why and what is PHP?

PHP Variables hold PHP data and it start with $ sign:

PHP variable can have a short name (like a and b) or a more descriptive name (class, name, average_time).
Rules for PHP variables:
PHP variable starts with the $ sign, followed by the name of the variable
PHP variable name must start with alphabet or the underscore character
PHP variable name cannot start with a numeric value
PHP variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) without any other special characters
PHP variable names are case-sensitive ($class and $CLASS are two different variables)


$x = "Hello Friend!!!";
$young = 15;
$z_pad = 5.7;

How to assign PHP variables? see the example bellow :-

<?php
$x = "Hello Friend!!!";
$young = 15;
$z_pad = 5.7;
?>

What is an PHP Array?

An PHP array is a special variable which can hold more than one value at a time.

If you have a list of items storing the Cycle in single variables could look like this
$cycle1 = "Hero";
$cycle2 = "Herqulies";
$cycle3 = "Rexond";
$cycle4 = "Forzed";

An PHP array can hold many values under a single name and you can access the values by referring to an index number.

How to create an PHP array()

The PHP array() index always starts at 0 and PHP index can be assigned like this, see below :-
$cycles[0] = "Hero";
$cycles[1] = "Herqulies";
$cycles[2] = "Rexond";
$cycles[3] = "Forzed";

The PHP index can be assigned automatically like this, see below:
$cycles = array("Hero", "Herqulies", "Rexond", "Forzed");

<?php
$cycles = array("Hero", "Herqulies", "Rexond", "Forzed");
echo "I have " . $cycles[0] . ", " . $cycles[1] . ", " . $cycles[2] . " and " . $cycles[3];
?>

Using the count() Function, we can get the length of an Array

<?php
$cycles = array("Hero", "Herqulies", "Rexond", "Forzed");
echo count($cycles);
?>

Using the Loop Function, see below :-

<?php
$cycles = array("Hero", "Herqulies", "Rexond", "Forzed");
$arrlength = count($cycles);
for($a = 0; $a < $arrlength; $a++)
{
echo $cycles[$a];
echo "<br>";
}
?>

How to use PHP Syntax?

The PHP script is executed on the server and the result is sent back to the browser through HTML supporter.

A PHP script can be placed anywhere in the document. The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code. A PHP script starts with <?php and ends with ?>

See the example bellow :-

<?php
// Write the PHP code here
?>

Get the PHP code in your HTML document, see the example bellow :-

<html>
<body>
<?php
// Write the PHP code here
?>
</body>
</html>

What is comments in PHP?

Some line in PHP code is not executed as that is not the part the program. The purpose of those lines is to make the reader understand the code well. Therefore comment can be used for :-
To get remember, developer use this comment to keep a reminder about the programming that what actually was it about. In future those comment help to recall the exact purpose and help them to further modify.
Let other understand, other reader can easily understand the coding and purpose of that program with the help of comment.


What is PHP echo and print Statements?

Both echo and print are almost same, they are used to get output data to the screen but echo has no return value while print has a return value of 1 so it can be used in expressions, echo can take multiple parameters while print can take one argument, echo is marginally faster than print, so these are the small difference.

The PHP echo Statement, see the example :-

<?php
echo "<h1>This is PHP!!!</h1>";
echo "Hi PHP!!!<br>";
echo "Let me learn PHP!<br>";
echo "This ", "string ", "has ", "multiple parameters.";
?>

How to display output variables with the echo statement, see the example :-

<?php
$a1 = "I like to learn learn PHP ";
$a2 = " website.gyaann.com";
$b = 8;
$c = 2;
echo "<h1>$a1<h1>";
echo "from $a2<br>";
echo $b + $c;
?>

The PHP print Statement, see the example :-

<?php
print "<h1>This is PHP!!!</h1>";
print "Hi PHP!!!<br>";
print "Let me learn PHP!";
echo "Print ", "syntax ", "do not support ", "multiple parameters.";
?>

How to display output variables with the print statement, see the example :-

<?php
$x1 = "I like to learn learn PHP ";
$x2 = " website.gyaann.com";
$a = 16;
$b = 8;
print "<h1>$x1</h1>";
print "from $x2<br>";
print $a + $b;
?>

What is PHP Conditional Statements?

When we have to use different actions for different conditions then we can use conditional statements in our code to do this.

In PHP we have the following conditional statements, See below :-

if statement (If the condition is true)

else if statement (If this condition is true and other conditions are false)

else (If all the conditions are false)

switch statement (One by one to be executed)

PHP if, else if and else Statement, see the example below

<html>
<head><title>PHP Conditional statement</title></head>
<body>
<?php
$age = 12;
if ($age < 18)
{
echo "<center><h1>You are not adult!!!</h1></center>";
}
else if ($age >= 18 && $age <= 30)
{
echo "<center><h1>You are adult!!!</h1></center>";
}
else if ($age > 30 && $age <= 50)
{
echo "<center><h1>You are at your middle age!!!</h1></center>";
}
else
{
echo "<center><h1>You are old!!!</h1></center>";
}
?>
</body>
</html>

PHP switch Statement, see the example below

<html>
<head><title>PHP Switch statement</title></head>
<body>
<?php
$myage = 15;
switch ($myage)
{
case 10:
echo "You are 10 years old!";
break;
case 15:
echo "You are 15 years old!";
break;
case 20:
echo "You are 20 years old!";
break;
default:
echo "Your are not 10, 15 or 20 years old!";
}
?>
</body>
</html>

What is PHP Loop?

PHP while loops execute a block of code while the specified condition matches, see the example bellow :-

<html>
<head><title>PHP While Loop Event</title></head>
<body>
<?php
$num = 10;
while($num > 0)
{
echo "$num number <br>";
$num--;
}
?>
</body>
</html>

PHP for loops execute a block of code while the specified condition matches, see the example bellow :-

<html>
<head><title>PHP For Loop Event</title></head>
<body>
<?php
for ($num = 9; $num >= 0; $num--)
{
echo "$num number <br>";
}
?>
</body>
</html>

What is PHP function and how to use this PHP function?

The following are the PHP user defined functions, see bellow :-

PHP function is a set of codes that can be used repeatedly in a program application
PHP function not always execute immediately after a page loads in the browser
PHP function get executed by a call to the function, using program in an application

1st Example of function, see bellow :-

<html>
<body>
<head><title>PHP Function</title></head>
<?php
function myschool($name)
{
echo "My name is $name<br>";
}
myschool("Raju");
myschool("Rajesh");
myschool("Mintu");
myschool("Shila");
myschool("Gourav");
myschool("Meena");
myschool("Shiuly");
myschool("Shangita");
?>
</body>
</html>

2nd Example of function, see bellow :-

<html>
<body>
<head><title>PHP Function</title></head>
<?php
function myschool($name, $class)
{
echo "My name is $name and I read in class $class<br>";
}
myschool("Raju", "4");
myschool("Rajesh", "8");
myschool("Mintu", "6");
myschool("Shila", "2");
myschool("Gourav", "11");
myschool("Meena", "7");
myschool("Shiuly", "5");
myschool("Shangita", "9");
?>
</body>
</html>
echo "My name is $name and I read in class $class<br>";

How can PHP upload files?

It is easy to upload files to the server using PHP, see the following bellow :-

First you have to create The HTML Form
Complete Upload File PHP Script, you have to create the PHP upload file script
Complete Upload File PHP ScriptIn third step, we have to check if file already exists or not
Complete Upload File PHP ScriptWe have to limit the limit file size
Complete Upload File PHP ScriptWe have to limit file type
Complete Upload File PHP ScriptWe have to complete the upload file PHP script

Here we have created the HTML Form

File Name: form.html

<html>
<head><title>PHP Upload File</title></head>
<body>
<center>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Upload Image: </label>
<input type="file" name="img" id="img">
<input type="submit" value="Upload" name="submit">
</form>
</center>
</body>
</html>

Here we have you have created the PHP upload file script. PHP script has the following :-

$target_dir = "upload/" specifies the location and folder where the file is going to store
$target_file specifies the location and path of the file to be uploaded
$imageFileType hold the file extension of the file
Next will check if the image file is an actual image or a false one

File Name: upload.php

<?php
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"]))
{
$check = getimagesize($_FILES["img"]["tmp_name"]);
if($check !== false)
{
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
}
else
{
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file))
{
echo "Sorry, this file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["img"]["size"] > 1000000)
{
echo "Sorry, your file is over 1000kb.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"&& $imageFileType != "gif" )
{
echo "Sorry, only JPG, JPEG, PNG & GIF files will support.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0)
{
echo "Sorry, unable to uploaded your file.";
// if everything is ok, try to upload file
}
else
{
if (move_uploaded_file($_FILES["img"]["tmp_name"], $target_file))
{
echo "The file ". basename( $_FILES["img"]["name"]). " has been uploaded.";
}
else
{
echo "Sorry, found an error uploading your file.";
}
}
?>

We need to use the unlink() function to delete file, See the example bellow :-

Syntax is unlink(Filename,Context)
FilenameRequired. Specifies the file to delete
ContextOptional. Specifies the context of the file handle
<?php
$file = "img.jpg";
if (!unlink($file))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $file");
}
?>

To delete a file from a directory, See the example bellow :-

<?php
$location="upload/img.jpg";
if(unlink($location)) echo "The file img.jpg has been deleted";
?>

To delete bulk files from a directory, See the example bellow :-

<?php
$allfiles = glob('upload/*'); //get all file names in an array
foreach($allfiles as $temp)
{
if(is_file($temp))
unlink($temp); //delete each file at a time until the last file is deleted
}
?>

We need to use the rename() function to rename a file, See the example bellow :-

Syntax is rename(oldname,newname,context)
OldnameRequired. Specifies the file or directory to be renamed
NewnameRequired. Specifies the new name of the file or directory
ContextOptional. Specifies the context of the file handle
To change the directory or folder name See the example bellow :-
<?php
rename("image","picture"); //existing directory name (image) will be renamed by (picture)
?>
To change the subdirectory name See the example bellow :-
<?php
rename("upload/image","upload/picture"); //existing directory name (image) will be renamed by (picture) in [upload] folder
?>
To change the file name See the example bellow :-
<?php
rename("file1.txt","file2.txt"); //existing file name (file1.txt) will be renamed by (file2.txt)
?>
To change the file name in a folder See the example bellow :-
<?php
rename("upload/file1.txt","upload/file2.txt"); //existing file name (file1.txt) will be renamed by (file2.txt) in [upload] folder
?>


See the following MySql Queries :-

SHOW DATABASES;
This query will show all the databases list
CREATE DATABASE mydatabase;
This query will create a databases name my database
USE mydatabase;
This query will use the database name mydatabase
CREATE TABLE mytable (Roll int(4), FirstName varchar(20), LastName varchar(20), Address varchar(40), City varchar(20));
This query will create a table 'mytable' in database 'mydatabase'
CREATE TABLE mytable1 (Roll int(4) PRIMARY KEY, FirstName varchar(20), LastName varchar(20), Address varchar(40), City varchar(20));
This query will create a table 'mytable1' with a 'PRIMARY KEY', this key is use to avoid duplicate entries
CREATE TABLE mytable2 (Roll int(4) PRIMARY KEY AUTO_INCREMENT, FirstName varchar(20) NOT NULL, LastName varchar(20) NOT NULL, Address varchar(40) NOT NULL, City varchar(20) NOT NULL);
This query will create a table 'mytable2', the 'PRIMARY KEY' and 'AUTO_INCREMENT' will automatically increase the value with each entry and 'NOT NULL' will not allow any blank field entry
DESC mytable1;
This query will show all details and datatype of table name mytable1
DROP DATABASE mydatabase;
This query will delete the database name mydatabase
DROP TABLE mytable;
This query will delete the table name mytable
DELETE FROM mytable1 WHERE ROLL='1';
This query will delete the specified row or rows from mytable1 which satisfy the condition
UPDATE mytable1 SET City='Bally' WHERE ROLL='1';
This query will update the specified field or fields from mytable1 which satisfy the condition
INSERT INTO mytable1 (FirstName, LastName, Address, City)values('Rahul', 'Gupta', 'Serampore Hooghly', 'Serampore');
This query will insert data into table name mytable1
ALTER TABLE mytable1 add COLUMN State Varchar(20);
This query will add a column name State in table name mytable1
ALTER TABLE mytable1 MODIFY COLUMN State Varchar(10) NOT NULL;
This query will modify the column name State as not null varchar(10) in table name mytable1
ALTER TABLE mytable1 CHANGE COLUMN State Country Varchar(10) NOT NULL;
This query will change the column name State to Country in table name mytable1
ALTER TABLE mytable1 DROP COLUMN Country;
This query will delete the column name Country in table name mytable1
SELECT * FROM mytable1;
When the SQL query above is run, it will return all records from table name mytable1
SELECT FirstName, LastName FROM mytable1;
When the SQL query above is run, it will return only the FirstName and LastName records from table name mytable1
SELECT FirstName, LastName FROM mytable1 WHERE Roll='2';
When the SQL query above is run, it will return FirstName and LastName of Roll 2 candidate from table name mytable1
SELECT * FROM mytable LIMIT 10;
When the SQL query above is run, it will return the first 10 records out of table, if it contains more than 10 records
SELECT TOP 10 * FROM mytable;
The above query will return first 10 records form the table
SELECT TOP 4 Name, Age FROM mytable WHERE Class=9;
The above query will return first 4 name and age of class 9 students form the table
SELECT * FROM mytable LIMIT 5 OFFSET 10;
or
SELECT * FROM mytable LIMIT 10, 5;
Both the above queries will return the same result, when the SQL queries will run, it will return 5 records and start from record number 11
SELECT * FROM mytable ORDER BY Marks DESC;
or
SELECT * FROM mytable ORDER BY Marks ASC;
The above first query will return all records in respect of marks in descending order and the second queries will return the same records in ascending order
SELECT Name FROM mytable WHERE Class=9 ORDER BY Marks DESC;
When we run the above queries then it return all names of class 9 students in descending order
SELECT Name FROM mytable WHERE Class IS NOT NULL;
The above query will return name from table where the class field is not empty or the class field has some value. Table also accept null data, null data means no data in that particular field
SELECT MIN(Class)FROM mytable WHERE Age=10;
or
SELECT MAX(Class)FROM mytable WHERE Age=10;
The above queries will return the minimum and maximum class of 10 years old student, if that combination is present on table
SELECT COUNT(Name)FROM mytable WHERE Class=5;
When we run the above query then COUNT() function returns the number of rows that matches a specified condition
SELECT AVG(Age)FROM mytable WHERE Class=5;
When we run the above query then AVG() function returns the average of age
SELECT SUM(Marks)FROM mytable WHERE Class=5;
When we run the above query then SUM() function returns the total sum of the marks
SELECT * FROM mytable WHERE Name LIKE 'B%';
The above query will return all records, whose name is starting with "B"
SELECT * FROM mytable WHERE Name LIKE '%b';
The above query will return all records, whose name is ending with "b"
SELECT * FROM mytable WHERE Name LIKE '%b%';
The above query will return all records, whose name is having "b" in any position
SELECT * FROM mytable WHERE Name LIKE 'B_%_%';
The above query will return all records, whose name is starting with "B" and are at least 3 characters in length
SELECT * FROM mytable WHERE Name LIKE 'B%A';
The above query will return all records, whose name is starting with "B" and ending with a
SELECT * FROM mytable WHERE Name NOT LIKE 'B%';
The above query will return all records, whose name is not starting with "B"
SELECT * FROM mytable WHERE Name NOT LIKE 'B%A';
The above query will return all records, whose name is not starting with "B" and ending with "A"
SELECT * FROM mytable WHERE Class IN (7, 8, 9);
The above query will return all records of class 7, 8 and 9
SELECT * FROM mytable WHERE Name IN ('Ram', 'Sham', 'Jadu');
The above query will return all records of Ram, Sham and Jadu
SELECT * FROM mytable WHERE Age IN (SELECT Age FROM mytable2);
The above query will return all records of same ages from two tables
SELECT * FROM mytable WHERE Age NOT IN (SELECT Age FROM mytable2);
The above query will return all records of uncommon ages from two tables
SELECT * FROM mytable WHERE Age BETWEEN 5 AND 10;
The above query will return all records of students between the age of 5 to 10
SELECT * FROM mytable WHERE Age NOT BETWEEN 5 AND 10;
The above query will return all records of students whose age is not between 5 to 10
SELECT * FROM mytable WHERE (Age BETWEEN 5 AND 10) AND NOT Class IN (4,5,6);
The above query will return all records of students between the age of 5 to 10 but it will exclude the students reading in class 4, 5 and 6
SELECT * FROM mytable WHERE (Age NOT BETWEEN 5 AND 10) AND Name LIKE 'B%';
The above query will return all records of students whose name is starting with B and age is not between 5 to 10
SELECT mytable.Name, mytable2.FatherName FROM mytable INNER JOIN mytable2 ON mytable.Roll = mytable2.Roll;
The above query will return name and father's name from both mytable and mytable2, the JOIN clause is used to combine rows from two or more tables, based on a related column between them, the INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns. If there are records in the "mytable2" table that do not have matches in "mytable", these father's name will not be shown
SELECT mytable.Name, mytable2.FatherName FROM mytable LEFT JOIN mytable2 ON mytable.Roll = mytable2.Roll ORDER BY mytable.Marks;
The LEFT JOIN keyword returns all records from the left table (mytable), even if there are no matches in the right table (mytable2)
SELECT mytable.Name, mytable2.FatherName FROM mytable RIGHT JOIN mytable2 ON mytable.Roll = mytable2.Roll;
The RIGHT JOIN keyword returns all records from the right table (mytable2), even if there are no matches in the left table (mytable)
SELECT mytable.Name, mytable2.FatherName FROM mytable FULL OUTER JOIN mytable2 ON mytable.Roll = mytable2.Roll;
The FULL OUTER JOIN keyword returns all the rows from the left table (mytable), and all the rows from the right table (mytable2). If there are rows in "mytable" that do not have matches in "mytable2", or if there are rows in "mytable2" that do not have matches in "mytable", then also this rows will be listed
SELECT Name FROM mytable UNION SELECT Name FROM mytable2 ORDER BY Class;
If mytable or mytable2 have the same name then each name will only be listed once, because UNION selects only distinct values. We can also use UNION ALL keyword to select duplicate values
SELECT mytable.Name, COUNT(mytable2.Roll) AS NumberOfStudents FROM mytable2 INNER JOIN mytable ON mytable2.Roll = mytable.Roll GROUP BY Class;
The above query will return the total number of students in each class, The GROUP BY statement is use with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns
SELECT mytable.Name, COUNT(mytable2.Roll) AS NumberOfStudents FROM mytable2 INNER JOIN mytable ON mytable2.Roll = mytable.Roll WHERE Class = 5 OR Name = 6 GROUP BY Class HAVING COUNT(mytable2.Marks) > 50;
The above SQL statement will list if the students of class 5 or 6 have registered more than 50 marks, The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions
SELECT Name FROM mytable WHERE EXISTS (SELECT FatherName FROM mytable2 WHERE Roll = mytable.Roll AND Class = 9);
The above SQL statement will check existence of common roll in both mytable and mytable2 and return name and father's name of class 9 students
SELECT Name FROM mytable WHERE Roll = ANY (SELECT Roll FROM mytable2 WHERE class = 8);
The above SQL statement returns TRUE and lists the names if it finds ANY records in the mytable2 table that class = 8
SELECT mytable.Name, mytable2.Roll INTO studentdatabackup IN 'backupdata.mdb' FROM mytable LEFT JOIN mytable2 ON mytable.Roll = mytable2.Roll WHERE Class = 9;
The above SQL statement will copy all records of class 9 students in a new table called studentdatabackup of another database whose name is backupdata.mdb
SELECT * INTO newmytable FROM mytable WHERE 1 = 0;
The above SQL statement will create a blank table called newmytable
INSERT INTO newtable (Roll, Name, Age) SELECT Roll, FatherName, Age FROM mytable WHERE Class=9;
The above SQL statement will insert records of roll, name, age of class 9 students in a new table of name newtable from mytable
Aliases are used to give a temporary name to a table or colum of a table
An alias only exists for the duration of the query
SELECT SLNO, Roll, Name, Age, Sum(Marks) AS aliascolum FROM mytable;
The above query will create a temporary name of a colum in a table
SELECT SLNO, Roll, Name, Age FROM mytable AS aliasmytable;
The above query will create a temporary table
View is a virtual table based on the result set of an SQL statement
Create the view with the following query :-
CREATE VIEW ViewMytable AS SELECT SLNO, Roll, Name, Age, Marks FROM Mytable WHERE Age = 12;
We will call the view query as follow :-
SELECT * FROM ViewMytable;
The first SQL statement will create a virtual table and the second query will fetch data from that table in real time
Create the view with the following query :-
CREATE VIEW ViewMytable2 AS SELECT Roll, Name, Age FROM Mytable WHERE Age < (SELECT AVG(Age) FROM Mytable);
We will call the view query as follow :-
SELECT * FROM ViewMytable2;
The first SQL statement will create a virtual table containing of all students detail of age less than the aver[Currentage age and the second query will fetch data from that table in real time
Create the view with the following query :-
CREATE VIEW ViewMytable3 AS SELECT DISTINCT SLNO, Name, Age, Sum(Marks) AS TotalMarks FROM ViewMytable GROUP BY Name;
We will call the view query as follow :-
SELECT * FROM ViewMytable3;
The first SQL statement will create a virtual table containing total marks of each students and the second query will fetch data from that table in real time
SELECT * FROM ViewMytable3 WHERE Age < 12;
We can also add condition to the view as the query will fetch detail of those students whose age is less than 12
Create or Replace the view with the following query :-
CREATE OR REPLACE VIEW ViewMytable3 AS SELECT DISTINCT SLNO, Roll, Name, Age, Sum(Marks) AS TotalMarks FROM ViewMytable GROUP BY Name;
We will call the view query as follow :-
SELECT * FROM ViewMytable3;
The first SQL statement will modify or create a virtual table containing total marks of each students and the second query will fetch data from that table in real time
SELECT * FROM ViewMytable3 ORDER BY Age ASC;
We can also add colum to the virtual table
Delete view with the following query :-
DROP VIEW ViewMytable;
The above query will delete the virtual table

What is PHP and how to use Mysql with PHP?

PHP combined with MySQL use to develop in Windows and serve on a Unix platform :-

We can access data from database through PHP, where we can easily run all SQL queries within PHP tag

First we need to download PHP-MyAdmin WAMPSERVER 2.5 or Higher version then we need to install that in our system. After that keep your all Files and folders in www-directory. Run the WAMPSERVER always before you run any application or call any PHP files. Always type localhost/project-root-folder/filename.php in your browser to call or run any PHP file from the WAMPSERVER.

How to create Database by SQL query within PHP tag, see bellow :-

Before creating Database, we need to setup a connection with Database
Open a Connection to MySQL

Check out the following queries in your PHP application :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
// Creating a connection with database in local server at your personal PC // Localhost is the default name of the local server at your machine, where you have your PHP files and project // root is the username to access the database which is by default stay root of the local server at your machine, where you have your PHP files and project // Keep blank the password to access the database which is by default stay empty or blank of the local server at your machine, unless you assign a password to your PHP-MyAdmin Local server, where you have your PHP files and project
$conn = new mysqli($servername, $username, $password);
// Checking connection of this PHP file with the database in local server at your machine
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

How to create Create a MySQL Database Using MySQLi :-

The CREATE DATABASE statement is used to create a database in MySQL
See the example bellow :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
// Creating connection with localhost server
$conn = new mysqli($servername, $username, $password);
// Checking connection with the localhost server
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Creating database in localhost server database
$sql = "CREATE DATABASE mydatabase";
if ($conn->query($sql) === TRUE)
{
echo "mydatabase created successfully";
}
else
{
echo "Error creating mydatabase: " . $conn->error;
}
$conn->close();
?>

How to create Create a MySQL Table :-

After creating Database we have to create Mysql Table
The most important thing is to know the data type, that we have to specify for different column
NOT NULL :- Each row must have a value for that column, null values are not accepted
DEFAULT value :- Set a default value when no other value is passed by the user
UNSIGNED :- Used for number types values and limits the stored data to positive numbers
AUTO INCREMENT :- MySQL automatically increases the value of that specific field by 1 each time a new record is added to the table
PRIMARY KEY :- Every row of a table will be uniquely identify and the column with PRIMARY KEY setting is often an ID number and is often used with AUTO_INCREMENT type
See the example below :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$sql = "CREATE TABLE mytable (
Roll INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Age INT(10),
Class INT(10) NOT NULL,
Marks INT(10)
)";
// VARCHAR is Character Variable and INT is Numeric Variable. This number in first bracket() denote the number of character or number to be stored maximum in that colum.
if ($conn->query($sql) === TRUE)
{
echo "Table mytable created successfully";
}
else
{
echo "Error creating table mytable: " . $conn->error;
}
$conn->close();
?>

How to insert data into Table of a Database :-

After creating Database and Table we have to insert data
The most important thing is to know the data type, that we have to specify data type for each specific colum
NOT NULL :- Each colum must have a value inserted, if you do not enter any value it takes sometimes default value as NULL
See the example below :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Inserting data into Table name mytable of Database name mydatabase, there are four colum of Name, Age, Class, Marks where the data Bittu, 20, 12, 99 are inserting and the Roll will be added automatically with adding one every times when the data is added to the table.
$sql = "INSERT INTO mytable (Name, Age, Class, Marks)
VALUES ('Bittu', '20', '12', '99')";
if ($conn->query($sql) === TRUE)
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "" . $conn->error;
}
$conn->close();
?>

How to select data from Table of a Database :-

After creating Database and inserting data into database
The most important thing is to know that how we can select and fetch those data in our page
See the example below :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Selection of data from table name mytable of Database name mydatabase, data from four colum Name, Age, Class, Marks will be selected as Bittu, 20, 12, 99 will be shown as output in the page.
$sql = "SELECT Name, Age, Class, Marks FROM mytable";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo "My name is: " . $row["Name"]. " and my age is: " . $row["Age"];
echo "<br>";
echo "I read in class: " . $row["Class"]. " and I score: " . $row["Marks"]. " marks in class test";
echo "<br><br>";
}
}
else
{
echo "0 results";
}
$conn->close();
?>

How to update data in Table of a Database :-

After creating Database, inserting data and fetching data into database
It is most important to know that how we can update those data in table
See the example below :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Updating data in table name mytable of Database name mydatabase, Marks will be update in table by specific Name as marks of Bittu will be update to 80 from 80.
$sql = "UPDATE mytable SET Marks=80 WHERE Name='Bittu'";
if ($conn->query($sql) === TRUE)
{
echo "Record updated successfully";
}
else
{
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>

How to delete data in Table of a Database :-

After creating Database, inserting data, fetching data and updating data in table of a database
It is sometimes required to delete data from table of a database and how to do that
See the example below :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Delete data in table name mytable of Database name mydatabase, Full Row will delete by specific Colum by colum name Bittu, its respective data will delete.
$sql = "DELETE FROM mytable WHERE Name='Bittu'";
if ($conn->query($sql) === TRUE)
{
echo "Record deleted successfully";
}
else
{
echo "Error deleting record: " . $conn->error;
}
$conn->close();
?>

How to Prepared Statements and Bound Parameters :-

After creating Database, inserting data, fetching data, updating data and deleating data in table of a database
It is necessary to know and learn to Prepared Statements and Bound Parameters
See the example below :-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Prepared Statements and Bind
$stmt = $conn->prepare("INSERT INTO mytable (Name, Age, Class, Marks) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $name, $age, $class, $marks);
// Set Parameters and Execute
$name = "Subhas Ghosh";
$age = "14";
$class = "10";
$marks = "80";
$stmt->execute();
$name = "Gopal Chandra";
$age = "16";
$class = "11";
$marks = "88";
$stmt->execute();
$name = "Bidhra Mallik";
$age = "13";
$class = "8";
$marks = "90";
$stmt->execute();
$name = "Nilesh Roy";
$age = "17";
$class = "12";
$marks = "70";
$stmt->execute();
echo "New records created successfully";
$stmt->close();
$conn->close();
?>

How to create user interface to accept user data into database :-

<html>
<head>
<title>Test</title>
</head>
<body>
<center>
<form action="test.php" method="post" enctype="multipart/form-data">
<center><h4><b>Registration Form</b></h4></center>
<div>
<label>Name: </label>
<input type="text" placeholder="Enter your Name" required="required" name="name">
</div>
<br>
<div>
<label>Age: </label>
<input type="number" placeholder="Enter Your Age" required="required" name="age">
</div>
<br>
<div>
<label>Class: </label>
<input type="number" placeholder="Enter Your Class" required="required" name="class">
</div>
<br>
<div>
<label>Marks: </label>
<input type="number" placeholder="Enter Your Marks" required="required" name="marks">
</div>
<br>
<div>
<input type="submit">
</div>
<br>
</form>
</center>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
echo '<div style="display:none;">';
$name = $_POST["name"];
$age = $_POST["age"];
$class = $_POST["class"];
$marks = $_POST["marks"];
echo '</div>';
$sql = "INSERT INTO mytable (Name, Age, Class, Marks) VALUES ('$name', '$age', '$class', '$marks')";
$conn->query($sql) === TRUE;
$sql = "SELECT Name, Age, Class, Marks FROM mytable";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo '<center>';
echo "My name is: " . $row["Name"]. " and my age is: " . $row["Age"];
echo "<br>";
echo "I read in class: " . $row["Class"]. " and I score: " . $row["Marks"]. " marks in class test";
echo "<br><br>";
echo '</center>';
}
}
else
{
echo "0 results";
}
$conn->close();
?>
</body>
</html>

User interface to accept data into database using (Prepared Statements and Bound Parameters) :-

<html>
<head>
<title>Test</title>
</head>
<body>
<center>
<form action="test.php" method="post" enctype="multipart/form-data">
<center><h4><b>Registration Form</b></h4></center>
<div>
<label>Name: </label>
<input type="text" placeholder="Enter your Name" required="required" name="name">
</div>
<br>
<div>
<label>Age: </label>
<input type="number" placeholder="Enter Your Age" required="required" name="age">
</div>
<br>
<div>
<label>Class: </label>
<input type="number" placeholder="Enter Your Class" required="required" name="class">
</div>
<br>
<div>
<label>Marks: </label>
<input type="number" placeholder="Enter Your Marks" required="required" name="marks">
</div>
<br>
<div>
<input type="submit">
</div>
<br>
</form>
</center>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Prepared Statements and Bind
$stmt = $conn->prepare("INSERT INTO mytable (Name, Age, Class, Marks) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $name, $age, $class, $marks);
// Set Parameters and Execute
echo '<div style="display:none;">';
$name = $_POST["name"];
$age = $_POST["age"];
$class = $_POST["class"];
$marks = $_POST["marks"];
echo '</div>';
$stmt->execute();
$stmt->close();
$sql = "SELECT Name, Age, Class, Marks FROM mytable";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo '<center>';
echo "My name is: " . $row["Name"]. " and my age is: " . $row["Age"];
echo "<br>";
echo "I read in class: " . $row["Class"]. " and I score: " . $row["Marks"]. " marks in class test";
echo "<br><br>";
echo '</center>';
}
}
else
{
echo "0 results";
}
$conn->close();
?>
</body>
</html>

Contact Address

Contact No9432590048
Email IDrunnhuntergo@gmail.com
Address409/B/1 Criper Road
Konnagar, Hooghly
West Bengal, India
Developed by :-Biswajit Mukherjee