Featured Post Today
print this page
Latest Post

Complete Self Controlled Form : Full Validations and Features with $_POST[] Method

According to new research, many hackers are working together to hack many sites. Now everyone is familiar with PHP, xHTML, CSS working and they can hack your form by
  • Save page as
  • Code checking
  • Firebug tool
  • Ctrl+U
So you need to make your contact form secure to safe your information..
I made this form to make your site more secure.
This form consists on some parts:
  1. Validate Function
  2. Values Validating
  3. Characters Limit Error Message
  4. Left Field Error Message
  5. Auto Selected fields after redirection
  6. CSS
  7. Form Fields
  8. Form Results
  9. Form Error Message
This form is divided into parts, anyone can easily understand it.
In this form : characters limit is
 'name' => 20, 'number' => 16, 'email' => 35,'subject' => 50, 'message' => 350, 'website' => 50

You can change it according to yourself.


  <?php  
           #######################################  
           #   Form Validation Function Start    #  
           #######################################  
      function form_validation($input)  
      {  
           $input = trim($input);  
           $input = htmlspecialchars($input);  
           $input = stripcslashes($input);  
           return $input;  
      }
   function validate_number($input_number)
   {  
   $input_number = preg_match ("/^[0-9]*$/", $input_number);
   $input_number = trim($input_number);  
            $input_number = htmlspecialchars($input_number);  
            $input_number = stripcslashes($input_number);
   return $input_number;
   }
   function validate_name($input_name)
   {  
   $input_name = preg_match("/^[a-zA-Z ]*$/", $input_name);
   $input_name = trim($input_name);  
            $input_name = htmlspecialchars($input_name);  
            $input_name = stripcslashes($input_name);
   return $input_name;
   }
   function validate_email($input_email)
   {  
   $input_email = preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $input_email);
   $input_email = trim($input_email);  
            $input_email = htmlspecialchars($input_email);  
            $input_email = stripcslashes($input_email);
   return $input_email;
   }
   function validate_web($input_web)
   {  
   $input_web = preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $input_web);
   $input_web = trim($input_web);  
            $input_web = htmlspecialchars($input_web);  
            $input_web = stripcslashes($input_web);
   return $input_web;
   }
   
           ######################################  
           #   Form Validation Function end     #  
           ######################################  
 /*--------------------------------------------------------------------------------*/  
           ####################################################
           #   Getting All Values and Validating them Start   #  
           ####################################################
                $error_msg = ""; //this variable for error massage  
    $departments = array(); //this array for saving department
                $name = $number = $email = $birth = $gender = $subject = $website = $select = $message = $color = ''; // we show all variables empty  
           ###############################################################  
           #   Submit Button Processing with secure validation Start     #  
           ###############################################################                      
                
    if(isset($_POST['submit']))  
                {  
                     $fields = array('name', 'number', 'email', 'birth', 'gender', 'departments', 'select', 'website', 'subject', 'message', 'color'); // all values field array  
      $errors = array(); //this array for saving errors 
                     foreach ($fields as $field) //this is for getting values  
                     {  
                          if(!isset($_POST[$field]) || $_POST[$field] == '' && $field != 'color') //if field value is empty or has nothing  
                          {  
                               array_push($errors, $field); //then selective field array value will be saved in error array.  
                          }  
                          else //if submit button has run, then it else will run  
                          {  
                               if($field != 'departments') //but if value is other than department field  
                               {  
                                    $$field = form_validation($_POST[$field]); //It will go through user define function and value will be made variables  
                               }  
                               elseif($field == 'departments') //but if value is about department then  
                               {  
                                    $departments = array(); //we define an array to save department values  
                                    $test_dept = $_POST[$field]; //we get department here  
                                    foreach($test_dept as $dept ) //we used departments parameter to save that on dept  
                                    {  
                                         array_push($departments, form_validation($dept)); //department will be fully validate and saved to department array  
                                    }  
                               }
                          }
        if($field == 'select' && $_POST[$field] == 'Navigation')
        {
         !array_push($errors, form_validation($field));
        }
                     } //this is foreach loop end  
                ##################################################  
                #   Getting All Values and Validating them end   #  
                ##################################################  
                ###########################################################################  
                # If No Error than Check characters Limit and show exceed Massage Start   #  
                ###########################################################################           
                          //As we have saved error values in errors array  
                     if(empty($errors) || !empty($errors))  
                     {  
                          //we define a assosiative array to define characters limit  
                          $fields = array('name' => 20, 'number' => 16, 'email' => 35,'subject' => 50, 'message' => 350, 'website' => 50);   
                          //For checking lenght we need to add a loop  
                          foreach($fields as $field => $length) //foreach loop is used for arrays : $field => $length we used for assosiative array  
                          ## in this $field => $length : $length variable as assigned to values  
                          {  
                               if (strlen($_POST[$field]) > $length)  
                               {  
                                    array_push($errors, $field . ' field characters limit has exceeded.'); //we shall use $field variable here,   
                                    # Because we are not using $fields, we are using $field as referance.   
                               }
          if($field == 'number' && !validate_number(($_POST[$field]))) //it is to validate number field.
          {
           array_push($errors, $field . " is not proper number."); //if there is an error in number field , error would be push on error array
          }
          if($field == 'name' && !validate_name(($_POST[$field]))) //it is to validate number field.
          {
           array_push($errors, $field . " is not proper name."); //if there is an error in number field , error would be push on error array
          }
          if($field == 'email' && !validate_email(($_POST[$field])) && !empty($_POST[$field])) //it is to validate number field.
          {
           array_push($errors, $field . " is not proper email."); //if there is an error in number field , error would be push on error array
          } 
          if($field == 'website' && !validate_web(($_POST[$field])) && !empty($_POST[$field])) //it is to validate number field.
          {
           array_push($errors, $field . " is not proper website link."); //if there is an error in number field , error would be push on error array
          } 
                          }  
                     } //it is if emtpy end  
                ########################################################################## 
                # If No Error than Check characters Limit and show exceed Massage End    #  
                ##########################################################################      
                ##################################################### 
                # If Error than then show the errors fields start   #  
                ##################################################### 
                     if(!empty($errors))  
                     {  
                          $error_msg = '<b>There are errors in following fields:</b> <br />';  
                          $error_msg .= implode('<br />', $errors);   
                     } //it is if not empty end  
                #########################################################  
                # If Error than then show the errors fields end         #  
                #########################################################  
                } //if isset POST['submit'] end  
           ###############################################################  
           #   Submit Button Processing with secure validation End       #  
           ###############################################################                      
 ?>  
 <!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" lang="us-en">  
 <head>  
 <title><?php $pagetitle="Self Controlled Form : Full Contact Form Feachers : Samee Ullah Feroz";
      define("blogname","www.QWC.me");
     echo $pagetitle ." : ". blogname; ?></title>
               <meta name="description" content="<?php echo $pagetitle ?> : Buy it." />
               <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<style>
/*html
    {
        height:100%;
        width:100%;
        background:url(http://www.southsoft.co.za/images/mysql.jpg) center center no-repeat;
        background-position:center;
 You can also give local file path
    }*/
a:link 
    {
        color:#00F;
        text-decoration:none;
    }

body
    {
  color:#0000FF;
  font-family:"Courier New", Courier, monospace;
  /*background-image:url(http://www.getacho.com/download/phpcss/images/bg-color.png);
  background-repeat:repeat;
  background-attachment:fixed;*/
    }
    
 
#main
 {
  color: #0000FF;
  overflow: auto;
  padding: 10px;
  width: 100%;
 }
 
ul
 {
  
  list-style:square url("images/sqpurple.gif");
 }
#table_bg   
 {  
   border:0;  
   border-color:#000;   
      border-collapse:separate;  
   padding:3;
   padding-right:100px;
 }
.sidemsg  
 {  
      margin-top:60px;
   font-family:"Courier New", Courier, monospace;  
      font-size:16px;  
 }  

</style>               
 </head>  
 <body style="background-color:<?php echo $color?>; ">  
           <div id="main">
           <h1 align="center">Secure Self Controlled Contact Form.</h1> 
           <h2>Qualities</h2>
           <ul>
           <li>Secure from Hackers</li>
           <li>Fast Processing</li>
           <li>Single File Contact Form</li>
           <li>Show Error on characters limit exceeded</li>
           <li>Show Error on Wrong Name</li>
           <li>Show Error on Wrong Email</li>
           <li>Show Error on Wrong Website</li>
           <li>Show Error on Wrong number</li>
           <li>Numbers only digits not doubles</li>
           <li>Cannot select future date of birth</li>
           <li>Can select background custom color</li>
           <li>Can select required Department</li>
           <li>Can select required Agent</li>
           <li>HTML, Javascript etc. Don't work</li>
           <li>After getting errors, form will not reset</li>
           </ul>
           <blockquote>This form is coded to keep away your site from <b>Hackers</b>.</blockquote>
           <h2>Price</h2>
           <hp>You can purchase this form in 5$ just.</hp> 
           <b>Samee is Online On</b><br />
           <b>Company Site : </b><a href="http://www.getacho.com" target="_blank">Getacho Company</a><br />
           <b>Facebook : </b><a href="http://www.facebook.com/sameeullah.feroz" target="_blank">Samee Ullah Feroz</a><br />
           <b>Gtalk :</b> <a href="mailto:seo.getacho@gmail.com" target="_blank">SEO.Getacho</a><br />
           <b>Skype : </b><a href="skype:SEO.Getacho?call">SEO.Getacho</a><br />
           
           </div>
           <div id="table_bg">
               <table style="background-color:<?php echo $color?>; width: 100%;" align="center" >  
               <form action="self_controlled_form.php" method="post" >  
                    <tr><td><label for="name"><strong>Full Name:</strong></label></td>  
                    <td><input type="text" name="name" placeholder="Full Name" style="width:250px;" value="<?php echo $name;?>" /></td></tr>  
                    <tr><td><label for="number"><strong>Personal Number:</strong></label></td>  
                    <td><input type="text" name="number" placeholder="00923234223945" style="width:250px;" value="<?php echo $number;?>"/></td></tr>  
                    <tr><td><label for="email"><strong>Email:</strong></label></td>  
                    <td><input type="text" name="email" placeholder="i.e. mail@example.com" style="width:250px;" value="<?php echo $email;?>"/></td></tr> 
                    <tr><td><label for="website"><strong>Website:</strong></label></td>                   
                    <td><input type="text" name="website" placeholder="i.e. www.example.com" style="width:250px;" value="<?php echo $website;?>"/></td></tr                
                    ><tr><td><label for="gender"><strong>Your Gender:</strong></label></td>  
                    <td><input type="radio" name="gender" value="Male"   
                    <?php if($gender == 'Male' && !empty($gender))echo 'checked';?>/>Male  
                    <input type="radio" name="gender" value="Female"   
                    <?php if($gender == 'Female' && !empty($gender))echo 'checked';?>/>Female</td></tr>
                    <tr><td><label for="birth"><strong>Your DOB:</strong></label></td>                  
                    <td><input type="date" name="birth" value="<?php echo $birth;?>" max="<?php echo date();?>" min="1991-01-01" /></td></tr>  
                    <tr><td><label for="departments[]"><strong>Contact Departments:</strong></label></td>  
                    <td><input type="checkbox" name="departments[]" value="Marketing Department"   
                    <?php if(in_array('Marketing Department', $departments)&& !empty($departments))echo 'checked';?>/>Marketing Department <br /> 
                    <input type="checkbox" name="departments[]" value="Development Department"   
                    <?php if(in_array('Development Department',$departments)&& !empty($departments))echo 'checked';?>/>Development Department <br /> 
                   <input type="checkbox" name="departments[]" value="Finance Department"   
                    <?php if(in_array('Finance Department', $departments) && !empty($departments))echo 'checked';?>/>Finance Department </td></tr>  
             <tr><td><label for="select"><strong>Contact Agent:</strong></label></td>  
                    <td><select name="select">
                        <option value="Navigation">Navigation</option>
                           <option value="Online Agent" <?php if($select == 'Online Agent' && !empty($select))echo 'selected'; ?> >Online Agent</option>  
                           <option value="SEO, SMO Agent" <?php if($select == 'SEO, SMO Agent' && !empty($select))echo 'selected'; ?> >SEO, SMO Agent</option>  
                           <option value="SEM, SMM Agent" <?php if($select == 'SEM, SMM Agent' && !empty($select))echo 'selected'; ?> >SEM, SMM Agent</option>  
                           <option value="Development Agent" <?php if($select == 'Development Agent' && !empty($select))echo 'selected'; ?> >Development Agent</option>  
                           <option value="Consultancy Agent" <?php if($select == 'Consultancy Agent' && !empty($select))echo 'selected'; ?> >Consultancy Agent</option>  
                           <option value="HR Agent" <?php if($select == 'HR Agent' && !empty($select))echo 'selected'; ?> >HR Agent</option>  
                    </select></td></tr>  
                    <tr><td><label for="subject"><strong>Subject:</strong></label></td>  
                    <td><input type="text" name="subject" placeholder="Type Subject" style="width:250px;" value="<?php echo $subject;?>"/></td></tr>  
                    <tr><td valign="top" align="left"><label for="message"><strong>Your Message:</strong></label></td>  
                    <td><textarea cols="40" rows="10" name="message" placeholder="Write your message"><?php echo $message;?></textarea></td></td>  
                    <tr><td valign="top" align="right"><input type="submit" value="Send" name="submit" /></td>  
                    <td>Choose the color :<input type="color" name="color" value="<?php echo $color; ?>" />
                    <br />This Feature Works on Chrome.
                    <br />Developed by <a href="mailto:sam@qwc.me">Samee Ullah Feroz</a><br /> Powered by : <a href="http://www.qwc.me">QWC.Me</a></td></tr>  
               </form>  
               </table>
               </div>
             <div class="sidemsg" style="background-color:<?php echo $color?>; ">  
            <h2>Results Here</h2>
             <?php  
                   echo $name . "<br />";  
                   echo $number . "<br />";  
                   echo $email . "<br />";
       echo $website . "<br />";  
                   echo $gender . "<br />";
                   echo $birth . "<br />";  
                   if (!empty($departments))
                   {
                       echo implode("<br />", $departments) . "<br />";
                   }
                   echo $select . "<br />";  
                   echo $subject . "<br />";            
                   echo $message . "<br />";  
                   echo $error_msg . "<br />";
                   ?>  
             </div>
 </body>  
 </html>

Form is complete with full security and limitations.

Instructions : This code is in-complete if you need this form, contact Samee Ullah Feroz

Demo : 
Ask For Installation
Consultant: 
On Facebook
Gtalk : SEO.Getacho@gmail.com
Skype : SEO.Getacho


0 comments

Secure Form of $_GET[] Method : Form Validation Function

secure form

Now I am going to post a form with full security, Check this
I made this form to get full detail from client that how can we deal with him.
still this contact form is incomplete but I'll complete it in further post.
I made a stylesheet.css file
Here ; I made id for table to use it. As we know, id is used for unique element. 


 @charset "utf-8";  
 /* CSS Document */  
 #table_bg   
 {  
      border:5px;  
      border:solid;  
      background-color:#0F9;  
      border-collapse:separate;  
 }  



Now I made a contact.html file
This form output is same as given image in this post.
I used table to align form perfectly


 <!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=iso-8859-1" />  
 <title>Contact Form</title>  
 <link rel="stylesheet" type="text/css" href="stylesheet.css" />  
 </head>  
      <body>  
           <table cellpadding="3" id="table_bg" align="center">  
           <form action="processing.php" method="get" >  
                <tr><td><label for="name"><strong>Full Name:</strong></label></td>  
                <td><input type="text" name="name" placeholder="Full Name" maxlength="20" style="width:250px;"/></td></tr>  
                <tr><td><label for="number"><strong>Personal Number:</strong></label></td>  
                <td><input type="text" name="number" placeholder="00923234223945" maxlength="16" style="width:250px;"/></td></tr>
                <tr><td><label for="email"><strong>Email:</strong></label></td>  
                <td><input type="text" name="email" placeholder="i.e. example@mail.com" style="width:250px;"/></td></tr>  
                <tr><td><label for="gender"><strong>Your Gender:</strong></label></td>  
                <td><input type="radio" name="gender" value="Male" />Male  
                <input type="radio" name="gender" value="Female"/ >Female</td></tr>  
                <tr><td><label for="department"><strong>Contact Department:</strong></label></td>  
                <td><input type="checkbox" name="department" value="Marketing_Department" />Marketing Department  
                <input type="checkbox" name="department" value="Development_Department" />Development Department</td></tr>  
       <tr><td><label for="select"><strong>Contact Person:</strong></label></td>  
                <td><select name="select" >  
       <option>Online Supporter</option>  
       <option>SEO, SMO Agent</option>  
       <option>SEM, SMM Agent</option>  
       <option>Development Agent</option>  
       <option>Consultancy Agent</option>  
       <option>HR Agent</option>  
       </select></td></tr>  
                <tr><td><label for="subject"><strong>Subject:</strong></label></td>  
                <td><input type="text" name="subject" placeholder="Type Subject" style="width:250px;"/></td></tr>  
                <tr><td valign="top" align="left"><label for="gender"><strong>Your Gender:</strong></label></td>  
                <td><textarea cols="50" rows="20" name="message" placeholder="Write your message"></textarea></td></td>  
                <tr><td>&nbsp;</td>  
                <td><input type="submit" value="Send" /> <input type="reset" value="Clear" /> </td></tr>  
           </form>  
           </table>  
      </body>  
 </html>  



Now I created a file processing.php
I needed to create this file for security. As we know, xHTML language runs on user side and PHP runs on Server side.
with $_GET[] Method, anyone can easily hack your code, that's why PHP is important to add creativity.
Features of Code:
  1. No value will be empty, User needs to enter all values
  2. If user will leave any value empty, form will redirect back to contact.html
  3. If user leaves spaces, form will trim them automatically
  4. HTML, Java code will not run in it.
  5. Back slash will not run in it
  6. User needs to write more than 25 characters in subject, more than 16 in message box, name maximum 20, number maximum 16



 <?php  
      require_once("form_validation.php");  
      #1st Form values should not be empty.   
      if (isset($_GET['name'] , $_GET['number'] , $_GET['email'], $_GET['gender'] , $_GET['department'], $_GET['select'], $_GET['subject'], $_GET['message'])  
      && $_GET['name']!="" && $_GET['number']!="" && $_GET['email']!="" && $_GET['subject']!="" && $_GET['message']!="")  
      {  
           if (strlen($_GET['name']) > 20 || strlen($_GET['number']) > 16 || strlen($_GET['email']) > 25 || strlen($_GET['subject']) < 25 || strlen($_GET['message']) < 160)  
                {  
                     header("Location: contact.html");  
                     exit;  
                }  
                $name = form_validation($_GET['name']);  
                $number = form_validation($_GET['number']);  
                $email = form_validation($_GET['email']);  
                $gender = $_GET['gender'];  
                $department = $_GET['department'];  
                $select = $_GET['select'];  
                $subject = form_validation($_GET['subject']);  
                $message = form_validation($_GET['message']);  
                echo "Name is : $name <br />  
                          Number is : $number <br />  
                               email is : $email <br />  
                                    Gender is : $gender <br />  
                                         Contact Department is : $department <br />  
                                              Subject is : $subject <br />  
                                                   Agent is : $select <br />  
                                                        Message is : $message <br />  
                ";  
           }  
           else  
           {  
                header("Location: contact.html");  
                exit;  
           }  
      ?>  

Now I created a function file with form_validation.php
In this function, it will use trim function to trim white spaces.
It will utilize HTML characters in whole form.
It will leave back slashes.


 <?php  
      function form_validation($input)  
      {  
           $input = trim($input);  
           $input = htmlspecialchars($input);  
           $input = stripcslashes($input);  
           return $input;  
      }  
 ?>  

Good Luck. Form is upgraded in further post.
5 comments

Function An Other Type : Variable Use In Function

You can define variable in function. But when you will call function at any place then you need to give the value to function. check this example.


 <?php  
      function hello($name) // Function starts from here. you need to define a variable here  
      {  
           echo "{$name} <br />"; // Here Function Detail   
      }  
      Hello("Samee"); // Don't forget to call the funtion.   
      Hello("Ullah"); # at calling time you need to add value to variable.   
      Hello("Feroz"); /* within double qoutes */  
 ?>  
0 comments

Basics : Simple User Define Function Creation

Function is used to make your programming easy. It is used as per-defined functions. You just need to write code once and after that you just need to call the function at anywhere in your whole script.
Read this simple code and learn from it.


 <?php  
      function hello() // Function starts from here. I made hello() function.  
      {  
           echo "Hello World"; // Here Function Detail   
      }  
      Hello(); // Don't forget to call the funtion.   
 ?>  
0 comments

Difference Between $_GET[] And $_POST[] : Brief Description


Both $_GET[] and $_POST[] are methods for sending HTTP requests, with or without forms.

  1. $_GET[] is method for querying data, basically any operation that doesn't cause changes on the server (like a search).
  2. $_POST[] is the opposite (like user registration, Posting comments on an article, etc...) Although the article is correct when saying that passwords should never be sent using $_GET[].
  3. $_GET[] IS NOT more secure than $_POST[], this is a very dangerous misconception.
  4. Also, the whole "$_GET[] is faster" thing is pointless, irrelevant and can lead to additional mistakes.
  5. Both methods are transparent.
  6. The only difference is that $_GET[] shows in the URL, but you can easily view $_POST[] data using tools such as Firebug or many others.
  7. Aside from that, both $_POST[] and $_GET[] requests can be exploited using widget.
  8. They are both communication methods, not intended to be more or less secure.
  9. It's our duty as programmers to validate, filter and apply security measures to ALL user input, no matter which method was used to send them.
  10. [Contribution : Er Galvão Abbott ] But we all already know this; no one is secure on internet.
  11. Anyone can track you, can try to hack you and your data. Some times it can be great lost of yours. So in development, we need to learn some methods and styles, which we can use for our safety.
  12. $_GET[] processing is fast than $_POST[] processing.
  13. Yes it is very little difference but we can not decline it. In $_GET[] Parameters are saved in browser history because of its URL part and but in $_POST[] Parameters never saved.
  14. In $_GET[] URLs can not bookmarked and saved but in $_POST[] you are not able to bookmark or save them.
Note : Don't $_GET[] Method, if you need to send important information like password, important information etc. try to use $_POST[] method in this time.
In $_GET[] you can use maximum 7607 characters easily, but in $_POST[] you can use 8 MB Maximum size. It is awesome limit.
Examples of $_GET[] Method :
http://www.qwc.me/index.php?FName=Samee+Ullah&LName=Feroz&Number=3234223945
Anyone can track you easily by it
Example of $_POST[] Method:
http://www.qwc.me/index.php
It is good for your security. and It is mostly used for SEO purpose.
0 comments

$_GET[] Simple Usage and Brief Description

$_GET[] is a PHP function. Mostly PHP Personal Functions starts from underscore "_".
$_GET[] is used to get value from other file. Example is shows bellow

I created 1st file with name : form.html


 <form action="index.php" method="get"> <!--Action is used to sand data to "index.php" file-->  
 <!--  
 ##################################################  
 # Table is used to align data with certain order #  
 ##################################################  
 -->  
 <table>  
 <tr><td><label for="FName">Type Your 1st Name:</label></td><td><input type="text" name="FName" placeholder="Type 1st Name" /></td></tr> <!--name attribute is used to get value at index.php-->  
 <tr><td><label for="LName">Type Your 1st Name:</label></td><td><input type="text" name="LName" placeholder="Type Last Name" /></td></tr> <!--placeholder is used to show guidance -->  
 <tr><td><label for="Number">Type Your 1st Name:</label></td><td><input type="text" name="Number" placeholder="Type your number" maxlength="10" /></td></tr>  
 <tr><td>&nbsp;</td><td align="left"><input type="submit" value="submit" /></td></tr> <!--&nbsp; is used to add spance-->  
 </table>  
 </form>  

Note : form.html was separate file and data is sent to index.php
Now I created 2nd file with name : index.php


 <?php   
      $fname = $_GET[FName]; // Here I got 1st name data   
      $lname = $_GET[LName]; # Here I got Last name data  
      $number = $_GET[Number]; /* Here I got number data */  
      //---------------------------------------------------------//  
      // I used different Comments styles above to remind them  //  
      // I used different Variables styles bellow to remind them //  
      //---------------------------------------------------------//  
      echo "User First Name is : {$fname} <br />"; # Variable with curly brackets within double qoutes  
      echo "User Last Name is : $lname <br />"; # Variable without curly brackets within double qoutes  
      echo "User Number is : " . $number # Variable with dot operator  
 ?>  


Here I got URL as :

http://www.qwc.me/index.php?FName=Samee+Ullah&LName=Feroz&Number=3234223945

Now try to understand this line

FName=Samee+Ullah&LName=Feroz&Number=3234223945 

Here you need to understand 3 things
after URL :
  1. http://www.qwc.me/index.php = URL Main Part
  2. ?  = Question Mark
  3.  FName=Samee+Ullah = Value

this value is sent to index.php
0 comments

New version PHP 5.5.4 has launched

PHP Versions
New PHP version 5.5.4 has launched at 19-Sep-2013 and in this version 30 several bugs have resolved but there was till some bugs. This was 5.4.20 Version. So many PHP users recommend to upgrade it more for better consistency. Then PHP 5.5.4 launched at 19-Sep-2013 and here was latest version. This version was announced immediately, this version fixes of several bugs against PHP 5.5.3. And after that all PHP users was encouraged to upgrade their system.

Updated:
PHP Version 5.5.9 has launched at 05-Feb-2014 and in this version many bugs related to PHP have fixed against PHP 5.5.8.

PHP Version 5.4.25 has launched at 06-Feb-2014 and PHP Development team announced that all PHP 5.4 users should update their versions. In this update many PHP 5.4.25.5 bugs have fixed.
0 comments

Palindrome an other script with using functions.

Palindrome an other script with using functions. Previous Palindrome Script was coded without using any function. In this function 3 methods are used,

  1. str_split() function
  2. var_dump() function
  3. implode() function
User will input any value consist on 5 digits, then str_split() will split your word / sentence to array. And 2nd var_dump() function will show the value, type of array, then implode() function is used to combine the value. 
check this code. try it
My friend Dan Edge helped me in it.
I thank to him.


 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">   
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->   
   Enter input 1:&nbsp;<input type="text" name="input" value="" /><br />   
   <input type="submit" name="submit" value="Submit" />   
 </form>   
 <?php  
   $inputs = array();   
   if (isset($_POST['input'])) //to check if the form was submitted   
   {   
     $inputs = str_split($_POST['input']);  
     var_dump($inputs);   
     if (count($inputs) == 5)   
     {      
       if(($inputs[0]==$inputs[4])&&($inputs[1]==$inputs[3]))   
       {   
         echo implode($inputs) . ' is a palindrome number. <br />';   
       }   
       else  
       {   
         echo implode($inputs) . ' is not a palindrome number. <br />';   
       }                       
     }                
     else   
     {   
       echo "Try Again : Enter 5 Digit Number. :(";   
     }   
   }   
 ?>  
0 comments

Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

I used many functions in this script. like Mod, Divide, Array Value Assigning, Float Function, then I used simple If .. else.. If conditional statement, and if within in statement.  
(Palindromes) A palindrome is a sequence of characters that reads the same backward as
forward.
For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and
11611.

Try this code. I hope you will learn from it.


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
 $dig = $inputs[0];  
 /*Now I need to get Mod 5th times from remaining value*/  
   $dig5 = ($dig % 10); //as mod of 10201 is 1 : $dig5 is Digit 5  
     $inputs[5] = $dig5; //1 is saved in 5th index  
   $dig4 = ($dig / 10); //value like 1020.1 : $dig4 is Digit 4  
     $dig4v = floor($dig4); //It will make 1020 : $dig4v is Digit 4th Value  
       $dig4vi = ($dig4v % 10); // as Mode of 1020 is 0 : $dig4vi is Digit 4th value index  
         $inputs[4] = $dig4vi; //0 is saved in 4th index  
   $dig3 = ($dig4v / 10); //value like 102.0 : $dig3 is Digit 3  
     $dig3v = floor($dig3); //It will make 102 : $dig3v is Digit 3rd Value  
       $dig3vi =($dig3v % 10); // as Mode of 102 is 2 : $dig3vi is Digit 3rd value index  
          $inputs[3] = $dig3vi; //2 is saved in 3rd index  
   $dig2 = ($dig3v / 10); //value like 10.2 : $dig2 is Digit 2  
     $dig2v = floor($dig2); //It will make 10 : $dig2v is Digit 2nd Value  
       $dig2vi = ($dig2v % 10); // as Mode of 10 is 0 : $dig2vi is Digit 2nd value index  
         $inputs[2] = $dig2vi; //0 is saved in 2rd index  
   $dig1 = ($dig2v / 10); //value like 1.0 : $dig1 is Digit 1  
     $dig1v = floor($dig1); //It will make 1 : $dig1v is Digit 1st Value  
       $inputs[1] = $dig1v; //1 is saved in 1st index  
 if (($inputs[0]>=10000)&&($inputs[0]<=99999))  
   {       
       if(($inputs[1]==$inputs[5])&&($inputs[2]==$inputs[4]))  
         {  
           echo "{$inputs[0]} is a palindrome number. <br />";  
         }  
       elseif(($inputs[1]!=$inputs[5])||($inputs[2]!=$inputs[4]))  
         {  
           echo "{$inputs[0]} is not a palindrome number. <br />";  
         }                                          
   }                           
 else  
   {  
     echo "Try Again : Enter 5 Digit Number. :(";  
   }  
 ?>  
0 comments

Write a script for Square of Asterisks?

I used nested loop in this script for creating square of Asterisks. I used for loop 1st then i used while loop within for loop and then I used if conditional statement to create break.
Try this code.


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
   for ($a=1 ; $a<= $inputs[0]; $a++)  
   {  
   $x = $inputs[0];  
   $y = 1;  
   while ($y <= $x)  
   {  
     echo "*";  
     if($y==$x)  
     {  
       echo "<br />";  
     }  
     $y++;  
   }  
   }  
 ?>  
0 comments

Write a script that prompts the user to enter the size of the side of a square and then displays a hollow square of that size made of asterisks. Your script should work for squares of all side lengths between 1 and 20.

For making Hollow Square of Asterisks, I need to use 3 times for loop. It is easy ; check this script.
You should try it.
User will enter a value and will get exact numbers of Asterisks Hollow Square:


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
 $less = ($inputs[0]-2);  
 for ($fl=1; $fl<=$inputs[0]; $fl++)  
   {  
     echo "*";  
     if ($fl==$inputs[0])  
       {  
         echo "<br />";  
       }  
   }  
 for ($hstr=1; $hstr<=$less; $hstr++)  
   {  
     echo "*" . str_repeat("&nbsp;", $less) . "* <br />";  
   }  
 for ($ll=1; $ll<=$inputs[0]; $ll++)  
   {  
     echo "*";  
   }  
 ?>  
0 comments

(Validating User Input) For any input, if the value entered is other than 1 or 2, keep taking input until the user enters a correct value.

Assignment is about to show that number is 1 and 2 or digit.
I used if else if statement here. and find great function.
Note : use this code. and try from different ways.


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
 <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
 Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
 <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
           $max = $inputs[0];  
           if ($max == 2)  
                {  
                     echo "Correct Value";  
                     die();  
                }  
           elseif ($max == 1)  
                {  
                     echo " Correct Value";  
                     die();  
                }  
           elseif ($max =! 1)  
                {  
                     echo " Not Correct Value. <br /> Try Again";  
                }  
           elseif ($max =! 2)  
                {  
                     echo " Not Correct Value. <br /> Try Again";  
                }  
           else  
                {  
                     echo "Try Again : Enter Digits";  
                }  
 ?>  
0 comments

Find Greatest Number from 10 inputs : PHP Assignment

I used input bar code in this assignment, which my teacher gave me to use. I used 10 input bars with different names. Then I used while loop and if conditional statement within loop to make this assignment successful.
Note : Try this code : Download Find Greatest Number Script


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   Enter input 2:&nbsp;<input type="text" name="input1" value="" /><br />  
   Enter input 3:&nbsp;<input type="text" name="input2" value="" /><br />  
   Enter input 4:&nbsp;<input type="text" name="input3" value="" /><br />  
   Enter input 5:&nbsp;<input type="text" name="input4" value="" /><br />  
   Enter input 6:&nbsp;<input type="text" name="input5" value="" /><br />  
   Enter input 7:&nbsp;<input type="text" name="input6" value="" /><br />  
   Enter input 8:&nbsp;<input type="text" name="input7" value="" /><br />  
   Enter input 9:&nbsp;<input type="text" name="input8" value="" /><br />  
   Enter input 10:&nbsp;<input type="text" name="input9" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
     $max = $inputs[0]; //this variable to store values to array  
     $count = 1; //this variable to run the loop 10 times  
     while ($count < 10) //here it is Terminate condition  
     {  
         if ($max < $inputs[$count])  
         {  
           $max = $inputs[$count];  
         }  
       $count++;  
     }  
     echo "$max is greatest <br/>";  
 ?>  
0 comments

Download Input text bar Script And Try this code

Now you can download input text bar script and can use this code directly to any site easily. Try this code.
when you will give any value to input box, that value will be saved to an array and you can get array detail at header. and can get value from it.
use it.
here $inputs is variable of array.
Note : Download Input Text Bar code and  use it to your site directly.


 <?php  
   $inputs = array();  
   if (isset($_POST['submit'])) { //to check if the form was submitted  
     $value = isset($_POST['input0'])? $_POST['input0'] : null;  
     for($count = 1; $value != null; $count++){  
       array_push($inputs, $value);  
       $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
     }  
   }  
   var_dump($inputs);  
   // to access specific index  
   // to take more then 3 inputs just add one more input field in form  
   //echo $inputs[0];  
   /*  
    *  
    *  
    *code here  
    *  
    *  
    *  
    */  
 ?>  
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   Enter input 2:&nbsp;<input type="text" name="input1" value="" /><br />  
   Enter input 3:&nbsp;<input type="text" name="input2" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
0 comments

Write a script which prints all the odd numbers. Output: 1 3 5 7 9 …

I used while loop in this script with if conditional statement within while. Here I used Mod (%) in if and get results till 55. try this code.
Script to print all odd numbers. 


                          <?php  
                               $num=0;  
                while ($num<=55)  
                               {  
                                         if ($num % 2 == 1)  
                                         {  
                                          echo $num . "<br />";  
                                         }  
                                    $num++;  
                               }  
                          ?>  
0 comments

Write a script that calculates and prints the sum of the integers from 1 to 10. Use a while statement to loop through the calculation and increment statements. The loop should terminate when the value of x becomes 11.

I used ; while loop for it and used if condition within while loop and add break for 1st loop.
code is given bellow understand it.


                          <?php  
                $num = 0;  
                               while ($num+1)  
                                    {  
                                         echo $num . "<br />";  
                                              if ($num==10)  
                                              {  
                                                   break 1;  
                                              }  
                                         $num++;  
                                    }  
                          ?>  
0 comments

Learn Foreach loop in php

Foreach loop is used in php to allocate array functionality in PHP Programming. Try this code and use it from different ways.


 <?php  
                $name = array("Sami", "ullah", "Feroz", "Sheikh"); //1st we need to define an array  
                               foreach ($name as $show) # We need to declare a custom variable from ourselves, value will be saved to custom variable  
                               {  
                               echo $show . "<br />";  
                               }  
 ?>  
0 comments

Simple For Loop in PHP

Learn basic for loop code in PHP. For Loop is like while loop but in this loop condition and increment is given within brackets after For statement.


 <?php  
                for ($num=1; $number<=10; $num++)  //Condition and Increment is defined here
                               {  
                               echo "$num <br />";  
                               }  
 ?>  
0 comments

Learn Simple While Loop in PHP

Now you can learn while loop very easily. Just you need to read code and understand the comments. try this code and implement on PHP Editor.


 <?php  
           $num=0; //1st we need to asign a value to varible   
                          while ($num <= 10) // Here we need to apply condition  
                          {  
                               echo "{$num}" . <br />; // here we need to show results  
                               $num++; // here we need to add increament.   
                          }  
 ?>  
0 comments

Get current month function with if else if statement

Try this code, you can learn that how to get current day, month, year in PHP. PHP will get complete data from your system setting and will print out. 


 <?php  
           $date = date("d M y"); //It is used to get current month , date , year  
                          echo $date . "<br />";  
           if ($date == "Sep")  
           {  
           echo "It is september";  
           }  
           else  
           {  
           echo "It is Octobar";  
           }  
                          ?>  
0 comments

Switch Statement in PHP

php switch statement

Switch statement is conditional statement. It is used same as if else if statement. It is used to find the best condition. Its simple code is given bellow


 <?php  
                          $name="Feroz"; //Need to asign a value to variable  
                switch ($name) //need to add variable which needs to optimise for condition  
                               {  
                                    case "Sami":   
                                    echo "I am Sami";  
                                    break;  
                                    case "ullah":  
                                    echo "I am Samee Ullah";  
                                    break;  
                                    case "sheikh":  
                                    echo "I am Sheikh";  
                                    break;  
                                    case "Feroz":  
                                    echo "I am Samee Ullah Feroz";  
                                    break;  
                                    default:  
                                    echo "I m Samee Ullah Feroz cast sheikh";  
                               }  
                          ?>  

Updated 22 Oct, 2013:
Some times, we forget to add break after completion of any case. It can create bug in your output. Because in this situation, code will execute other cases and also will show their outputs.
0 comments

PHP Array Important Functions : 8th Day Lecture of PHP

array functions in php

PHP Array Important Functions

PHP array_fill Function and its usage

Array ( [3] => Sheikh Ansari [4] => Sheikh Ansari [5] => Sheikh Ansari [6] => Sheikh Ansari )

PHP array_pop Function and its usage

Sheikh

PHP array_push Function and its usage

Array ( [0] => Samee [1] => ullah [2] => Feroz [3] => Sheikh )

PHP array_reverse Function and its usage

Array ( [0] => Sheikh [1] => Feroz [2] => Ullah [3] => Samee )

PHP array_search Function and its usage

2

PHP array_slice Function and its usage

Array ( [0] => Feroz [1] => Sheikh [2] => Ansari )
Array ( [0] => Feroz [1] => Sheikh )

PHP array_unique Function and its usage

Array ( [0] => Samee [1] => Ullah [2] => 3 [3] => Sheikh )

PHP count Function and its usage

5

PHP current Function and its usage

Samee

PHP next Function and its usage

Ullah
Feroz

PHP reset Function and its usage

Samee
Feroz
Samee

PHP shuffle Function and its usage

Array ( [0] => Sheikh [1] => Ansari [2] => Samee [3] => Feroz [4] => Ullah )

 <html>  
   <head>  
     <title><?php $pagetitle="PHP Array Important Functions ";  
                               define("blogname","Samee Articles");  
                          echo $pagetitle . ":" . blogname ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <div id="main">  
       <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
           <?php  
                               function b()  
                               {  
                               echo "<br />";  
                               }  
                          ?>  
       <h1 align="center"><?php echo $pagetitle ?></h1>  
          <h2 align="left">PHP array_fill Function and its usage</h2>  
                          <?php  
                $emp = array();  
                               $emp=array_fill(3,4,"Sheikh Ansari"); //it is used to fill the array ; 3rd value and remaining 4 values  
                               print_r($emp);  
                               b();  
                          ?>  
         <h2 align="left">PHP array_pop Function and its usage</h2>  
           <?php  
             $str = array("Samee","ullah","Sheikh");  
                               echo array_pop($str); //it is used delete the last element of the error and show it.  
                               b();  
                          ?>  
         <h2 align="left">PHP array_push Function and its usage</h2>  
           <?php  
             $str = array("Samee","ullah","Feroz");  
                               array_push($str,"Sheikh"); //it is used return the last value end of the array  
                               print_r($str);  
                               b();  
                          ?>  
         <h2 align="left">PHP array_reverse Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh");  
                               $name = array_reverse($str); //1st you need to asign complete array to an other variable; then you need to print out that array  
                               print_r($name);  
                               b();  
                          ?>  
         <h2 align="left">PHP array_search Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh");  
                               echo array_search("Feroz",$str); //It is used to find th element in array.  
                               b();  
                          ?>  
          <h2 align="left">PHP array_slice Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh", "Ansari");  
                               print_r (array_slice($str, 2)); //It is used to make a slice from 2nd value to end  
                               b();  
                               $str = array("Samee","Ullah","Feroz", "Sheikh");  
                               print_r (array_slice($str, 2, 3)); //It is used to make a slice from 2nd value to 3rd value  
                               b();  
                          ?>  
         <h2 align="left">PHP array_unique Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah",3, "Sheikh", "Samee");  
                               print_r (array_unique($str)); //It is used to remove duplicate value in the array  
                               b();  
                          ?>  
         <h2 align="left">PHP count Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah",3, "Sheikh", "Samee");  
                               print_r (count($str)); //It is used to count the values in array  
                               b();  
                          ?>  
         <h2 align="left">PHP current Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah",3, "Sheikh", "Samee");  
                               print_r (current($str)); //It is used to print 1st value of the array  
                               b();  
                          ?>  
         <h2 align="left">PHP next Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh", "Ansari");  
                               print_r (next($str)); //It is used to print (2nd value) next to 1st value of the array  
                               b();  
                               print_r (next($str)); //It is used to print (3rd value) next to next to 1st value of the array  
                               b();  
                          ?>  
         <h2 align="left">PHP reset Function and its usage</h2>  
           <?php  
                               $array = array('Samee', 'Ullah', 'Feroz', 'Ansari');  
                               echo current($array) . "<br />\n"; //1st element  
                               next($array);  
                               next($array); // skip two steps  
                               echo current($array) . "<br />\n";  
                               reset($array); //reset is used to reset the array elements.   
                               echo current($array) . "<br />\n";   
                               b();  
                          ?>  
         <h2 align="left">PHP shuffle Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh", "Ansari");  
                               shuffle($str); //It will shuffle array elements on every refresh  
                               print_r ($str);  
                          ?>   
   </body>  
 </html>  



0 comments

PHP Conditional Statements : If Else If Statements : 7th Day Lecture of PHP



PHP Conditional Statements : If Else If Statements

What is PHP Conditional Statements?

when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this
  1. If : executes some code only if a specified condition is true
  2. if...else statement - executes some code if a condition is true and another code if the condition is false
  3. if...elseif....else statement - selects one of several blocks of code to be executed

If Example

if...else Example

Have a good night!

if...elseif....else else Example

Have a good night!

 <html>  
   <head>  
     <title><?php $pagetitle="PHP Conditional Statements : If Else If Statements";  
                               define("blogname","Samee Articles");  
                          echo $pagetitle . ":" . blogname ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <div id="main">  
       <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
       <h1 align="center"><?php echo $pagetitle ?></h1>  
          <h2 align="left">What is PHP Conditional Statements?</h2>  
           <?php  
             echo "when you write code, you want to perform different actions for different decisions.<br>  
                               You can use conditional statements in your code to do this";  
                               echo "<ol type=\"A\">  
                                         <li>If : executes some code only if a specified condition is true</li>  
                                         <li>if...else statement - executes some code if a condition is true and another code if the condition is false</li>  
                                         <li>if...elseif....else statement - selects one of several blocks of code to be executed</li>  
                                         </ol>";  
           ?>   
          <h2 align="left">If Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
           ?>   
          <h2 align="left">if...else Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
                               else  
                                {  
                                echo "Have a good night!";  
                                }  
                          ?>  
         <h2 align="left">if...elseif....else else Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"10")  
                                {  
                                echo "Have a good morning!";  
                                }  
                               elseif ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
                               else  
                                {  
                                echo "Have a good night!";  
                                }  
                          ?>  
     <div id="sidebar">  
       <ul>  
            <li><?php echo "<a href=\"http://sameearticles.blogspot.com\">blogname</a>"?></li>  
         <li><a href="http://www.blogger.com/home">Blogger</a></li>  
         <li><a href="http://sameearticles.blogspot.com/search/label/PHP%20Learning">PHP Learning</a></li>  
         <li><a href="http://seoacquire.blogspot.com">SEO Knowledge</a></li>  
         <li>CSS Learning</li>  
       </ul>  
           </div>    
   </body>  
 </html>  


0 comments

Array Types in PHP : 7th Day Lecture of PHP


php arrays

Types of Array In PHP : Samee Articles

Sample 1 : Types of Array in PHP.

Types of Array In PHP
  1. Indexed arrays - Arrays with numeric index
  2. Associative arrays - Arrays with named keys
  3. Multidimensional arrays - Arrays containing one or more arrays

Sample 2 : Indexed Arrays Example And Use in PHP.

My 1st name is Samee.
My Last Name is Feroz
My Cast is Sheikh.
array (size=4)
  0 => string 'Samee' (length=5)
  1 => string 'Ullah' (length=5)
  2 => string 'Feroz' (length=5)
  3 => string 'Sheikh' (length=6)
Values in Array = 4

Sample 3 : Associative arrays Example And Use in PHP.

My 1st name is Samee .
My Last Name is Feroz
My Cast is Sheikh.
array (size=4)
  'firstname' => string 'Samee' (length=5)
  'middlename' => string 'Ullah' (length=5)
  'lastname' => string 'Feroz' (length=5)
  'cast' => string 'Sheikh' (length=6)

Sample 4 : Multidimensional arrays arrays Example And Use in PHP.

array (size=2)
  0 => 
    array (size=4)
      0 => string 'Samee' (length=5)
      1 => string 'Ullah' (length=5)
      2 => 
        array (size=1)
          0 => string 'Sheikh' (length=6)
      'cast' => string 'Sheikh' (length=6)
  1 => string 'Feroz' (length=5)
My 1st name last part is Ullah

 <html>  
   <head>  
     <title><?php $pagetitle="Types of Array In PHP : 6th Day Lecture : Samee";  
                          echo $pagetitle; ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="http://www.getacho.com/download/phpcss/stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
     <h1 align="center">Types of Array In PHP : <a href="http://sameearticles.blogspot.com" target="_blank">Samee Articles</a></h1>  
       <h2 align="left">Sample 1 : Types of Array in PHP.</h2>  
         <?php  
                          echo "Types of Array In PHP <br />";  
                          echo  
                          "<ol type=\"a\">  
                          <li>Indexed arrays - Arrays with numeric index</li>  
                          <li>Associative arrays - Arrays with named keys</li>  
                          <li>Multidimensional arrays - Arrays containing one or more arrays</li>  
                          </ol> <br />";  
         ?>  
       <h2 align="left">Sample 2 : Indexed Arrays Example And Use in PHP.</h2>  
         <?php  
                          $name = array("Samee", "Ullah", "Feroz"); //It is the way to add an index array  
                          $name[3]="Sheikh"; //It is the way to add a value to 3rd number of array, it is custom way  
                          echo "My 1st name is $name[0]. <br />";  
                          echo "My Last Name is " . $name[2] . "<br />";  
                          echo "My Cast is {$name[3]}. <br>";  
                          var_dump($name);  
                          echo "Values in Array = \t" . count($name); //this function is for counting the values of Array  
         ?>  
       <h2 align="left">Sample 3 : Associative arrays Example And Use in PHP.</h2>  
         <?php  
                          $name = array("firstname"=>"Samee","middlename"=>"Ullah","lastname"=>"Feroz"); #It is the way to add an assosiative array  
                          $name['cast'] = "Sheikh"; //you can use double or single qoutes both methods with in []  
                          echo "My 1st name is {$name["firstname"]} . <br />";  
                          echo "My Last Name is " . $name["lastname"] . "<br />";  
                          echo "My Cast is {$name["cast"]}. <br>";  
                          var_dump($name);  
         ?>  
       <h2 align="left">Sample 4 : Multidimensional arrays arrays Example And Use in PHP.</h2>  
         <?php  
                          $name= array(array("Samee","Ullah"),"Feroz"); //array within array is called multidimensional array  
                          /*$name[0][2][0]="Sheikh";*/ //1st way to write one integer between array  
                          $name[0]["cast"]="Sheikh"; //2nd way to write one integer between array  
                          var_dump($name);  
                          echo "My 1st name last part is ". $name[0][1]; //it is used to find the path  
         ?>  
   </body>  
 </html>  

0 comments
 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger