Google+ PHP TUTORIALS ONLINE HELP FOR MEDICAL AND PROGRAMMING: 2014-02-16

Saturday 22 February 2014

Multidimensional Array

Multidimensional Array

Today we are going to discus multidimensional array. A multidimensional array is an array containing one or more arrays.In this example we have used multidimensional arrays.

Example

<!DOCTYPE html>
<head>
<title>Multidimensional Array</title>
</head>
<body>
<?php
$cars= array
    (
    array("Honda",1000,100),
    array("BMW",60,59),
    array("Toyota",120,100)
    );
echo $cars[0][0].": Ordered: ".$cars[0][1].". Sold: ".$cars[0][2]."<br>";
echo $cars[1][0].": Ordered: ".$cars[1][1].". Sold: ".$cars[1][2]."<br>";
echo $cars[2][0].": Ordered: ".$cars[2][1].". Sold: ".$cars[2][2]."<br>";
?>
</body>
</html>

Output

Honda: Ordered: 1000. Sold: 100
BMW: Ordered: 60. Sold: 59
Toyota: Ordered: 120. Sold: 100

Friday 21 February 2014

Web Devloper


How to start PHP programming in windows?

How to start PHP programming in windows?


First of all I will teach you how to start PHP programming in windows? You will manually download PHP setup like as wamp server or xampp setup, than you will install in you computer after that gentare for icon . than you will restart in you system.Than you will click php setup after that, you will check  Apache Server and MySQL is running or not  running. If Apache server is running .
 
How to check Apache server is running or not

First of all you will open browse like as Mozilla Internet Explore  than you will type for http://localhost:81, Local host is running.and you will start php programming.In case Apache Server is not running than, you problem is port .port 81 is already in use. you can change port number (config.ex) files,  than Apache is running..
you can see below this image.....




Hello World Example

       Hello World Example

       <html>
       <head>
        <title>Hello World</title>
         </head>
        <h>Welcome my first PHP Page</h>

       // PHP script start with <?php code ?>
        
          <?php
            ECHO "Hello World!";

             ?>

          </html>

Output:-
         Welcome my first PHP Page.
                    Hello World

Tuesday 18 February 2014

PHP Data Types

PHP Data Types

Today i will teach you. how we can use PHP data types.
There are Seven types of PHP Data Types.
  1. String.
  2.  Integer.
  3.  Floating point numbers,
  4.  Boolean.
  5.  Array.
  6.  Object.
  7.  NULL.
String Data type:-The string is a sequence of characters. we can be any text inside quotes. we have used single or double quotes. you can see below in examples
Example of String Data types:-
<html>
<head>
<title>String data type</title>
</head>
<body>
<?php 
$x= "Hello PHP";
$y= "Welcome to PHP";
echo $x;
echo "<br>";
echo $y;
?>
</body>
</html>
Output
Hello PHP
Welcome to PHP
 Integer Data type:-Integer is a basic data types. We can assign which has no of fractional part to int type but int is a 2 Byte space.
Importants Rules:
Integer is a least one digit (0-9).
Integer cannot contain comma or blanks.
Integer must not have a decimal point.
Integer can be either positive or negative values.
Now we can assign a value between the above range below example. In this example we have used different variables like as negative number, hexadecimal number ,octal numbers and we have used PHP var_dump(); function returns the data type.
Example
<html>
<head>
<title>Integer Data types</title>
</head>
<body>
<?php 
$y = 4567;
var_dump($y);
echo "<br>"; 
$y = -254; // negative number 
var_dump($y);
echo "<br>"; 
$y = 0x8C; // hexadecimal number
var_dump($y);
echo "<br>";
$y = 047; // octal number
var_dump($y);
?> 

</body>
</html>
Output
int(4567)
int(-254)
int(140)
int(39)

Monday 17 February 2014

PHP form Validation Example

PHP form Validation Example

In this example, we have discus how to use PHP Form Validation. First off all we have displayed HTML form with text fields and submit button. In this example we have used  method and function. First thing we had done is to pass all variables through PHP's htmlspecalchars() function. After the we fills all input field than ,we click submit button and  display all input fields values. Now we have used $_SERVER["REQUEST_METHOD"]. If the REQUEST_METHOD is POST, and submitted form. If user not submit input fields skip the validation and display a blank form.

Example of PHP Validation:
<!DOCTYPE HTML> 
<html>
<head>
</head>
<body> 

<?php

$name = $email = $gender = $address = $mobile = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$mobile = test_input($_POST["mobile"]);
$address = test_input($_POST["address"]);
$gender = test_input($_POST["gender"]);
}

function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<table llpadding="2" width="20%" bgcolor="99FFFF" cellspacing="2" border="1">
<tr>
<td>Name:</td> 
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Moblie No:</td>
<td><input type="text" name="mobile"></td>
</tr>
<tr>
<td>Address</td>
<td> <textarea name="address" rows="5" cols="20"></textarea></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male</td>
</tr>
<tr>
<td>&nbsp; &nbsp;</td>
<td> <input type="submit" name="submit" value="Submit"> </td>
</tr>
</table>
</form>


<?php
echo "<h2><Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $mobile;
echo "<br>";
echo $address;
echo "<br>";
echo $gender;
?>

</body>
</html>
Output

PHP Form Handling

PHP Form Handling

We are going to discus How to use PHP Form Handling. In this below example we have displays a simple  HTML form, and displays for Four Input Fields and submit button. After that user fills all input fields and click the submit button, the form data is send for processing to a PHP files named "Display.php". We use for post method, Post methods is send data HTTP.
We have used echo() method. Echo is a language construct and we can use without parameter parentheses:
Syntax
  <?php echo $_POST["Firstname"]; ?>
Form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Handling</title>
</head>
<h>PHP Form Handling</h>
<body>
<pre>
<form action="Display.php" method="post">
First Name: <input type="text" name="Firstname" id="fname">
Last Name: <input type="text" name="lastname" id="lname">
Address: <input type="text" name="address" id="address" />
Mobile No: <input type="number" name="number" id="number"/>
<input type="submit" name="submit" /> 
</form> 
</pre>
</body>
</html>
Dispaly.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP welcome page</title>
</head>

<body>
Your First name is: <?php echo $_POST["Firstname"]; ?><br>
Your Last name is: <?php echo $_POST["lastname"]; ?><br>
Your Address is: <?php echo $_POST["address"]; ?><br>
Your Mobile number is: <?php echo $_POST["number"]; ?>
</body>
</html>

You can see below OutPut

PHP form Validation

PHP form Validation

We are going to discus how to use PHP Form Validation. Now First off all we have display HTML form with meny text fields and submit button First name, Lastname,MobileNo,PhoneNo Email, Address like so on In this example we have used many method and function. First thing we had done is to pass all variables through PHP's htmlspecalchars() function. After the we fills all input field than ,we click submit button and display all input fields values. Now we have used $_SERVER[REQUEST_METHOD]. If the REQUEST_METHOD is POST, and submitted form. If user not submit  all input fields than show for error massage please submit all  required fields and after that user click on the submit button than display all input fields
We have use for if and else statements
Example
<!DOCTYPE HTML> 
<html>
<head>
<style>
.error {color: #FF0000;}
body {
background-color: #D1D1D1;
}
</style>
<meta charset="utf-8">
</head>
<body> 

<?php
// Define variables and set to empty values:
$nameErr =$lnameErr = $emailErr = $mobilenoErr = $phonenoErr = $genderErr = $addressErr = "";
$name = $lname= $email = $mobileno = $gender = $address = $phoneno = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{

if (empty($_POST["name"]))
{$nameErr = "Name is required";}
else
{$name = test_input($_POST["name"]);}

if (empty($_POST["lname"]))
{$lnameErr = "Last Name is required";}
else
{$lname = test_input($_POST["lname"]);}

if (empty($_POST["email"]))
{$emailErr = "Email is required";}
else
{$email = test_input($_POST["email"]);}

if (empty($_POST["mobileno"]))
{$mobilenoErr = "Mobile No is required";}
else
{$mobileno = test_input($_POST["mobileno"]);}

if (empty($_POST["phoneno"]))
{$phonenoErr = "Phone No No is required";}
else
{$phoneno = test_input($_POST["phoneno"]);}



if (empty($_POST["address"]))
{$addressErr = "Address is required";}
else
{$address = test_input($_POST["address"]);}

if (empty($_POST["gender"]))
{$genderErr = "Gender is required";}
else
{$gender = test_input($_POST["gender"]);}

}

function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

<h2>PHP Form Validation Example</h2>

<table>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<tr>
<td>Name:</td>
<td> <input type="text" name="name"> <span class="error">* <?php echo $nameErr;?></span></td>

</tr>
<tr>
<td>Last Name:</td>
<td> <input type="text" name="lname"> <span class="error">* <?php echo $lnameErr;?></span></td>

</tr>

<tr>
<td> E-mail:</td>
<td> <input type="text" name="email"> <span class="error">* <?php echo $emailErr;?></span></td>
</tr> 

<tr>
<td> Mobile NO</td>
<td><input type="text" name="mobileno"> <span class="error">* <?php echo $mobilenoErr;?></span></td>
</tr> 

<tr>
<td>Phone No</td>
<td><input type="text" name="phoneno"> <span class="error">* <?php echo $phonenoErr;?></span></td>
</tr> 
<tr>
<td>Address:</td>
<td><textarea name="address" rows="5" cols="20"></textarea> <span class="error">* <?php echo $addressErr;?></span></td>
</tr> 
<tr>
<td> Gender:</td>
<td><input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<span class="error">* <?php echo $genderErr;?></span></td>
</tr> 

<tr>
<td>&nbsp;</td>
<td> <input type="submit" name="submit" value="Submit"> </td>
</tr>
</form>
</table>


<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $lname;
echo "<br>";
echo $email;
echo "<br>";
echo $mobileno;
echo "<br>";
echo $phoneno;
echo "<br>";
echo $address;
echo "<br>";
echo $gender;
?>

</body>
</html>

Output