Sunday, 24 April 2016

WEEK8_Class of PHP & Form

In this class, we are learning about new things - PHP and FORM.

OK, what is PHP. PHP is really good at handling data submitted to the server in HTML forms. HTML forms allow users to enter data into a web page.

Simple Form Precessing

<form METHOD= "GET"
           ACTION=  "process.php">


2 main attribute in a form :

1*METHOD
   Get/post

2*ACTION
    -used to specify the target which is where the data is to be transmitted.
    -the target is a file that contains code for processing.


$_GET variable

  • an array of variable names and value sent by the HTTP GET method
$_POST variable
  • an array of viarable names and values sent by the HTTP POST method.
$_REQUEST variable
  • contain the content of both $_GET, $_POST, $_COOKIES.
  • used to get the result from form data sent with both the GET and POST methods.


Example of Getting form value: 


Example of Displaying submitted values: 


Authentication using USERNAME & PASSWORD
  • allowing a user to access private information or preventing them from doing so.

Example of aunthenification



Managing Session
  • duration for which a user is connected to a site.
  • also as a block of information that stores variable and values.
  • feature: i. consist of an identification string.
i. to start a session and to track session variable across user session

session_start();

ii. to register a session

session_register (variable);

iii. to destroy a session

session_destroy();





WEEK 7_In Class

Today, our lecturer give us do some the exercise in class.

How to calculate the BMI using php code:

 

BMI Categories

Underweight = <18.5
Normal weight = 18.5-24.9
Overweight = 25-29.9
Obesity = BMI of 30 or greater

if ($BMI>= 30)
echo "obes";
elseif ($BMI>= 25)
echo "overweight";
elseif ($BMI>= 18.5)
echo "normal";
else
echo "underweight";





Picture when lecturer was explaining how to do question above XDXD 

WEEK 6_Lab Session - Doing some Exercise

These are the lab question that given by our lecturer.

Question 1.
 <?php
   $name = "Syamsul Bahrin Zaibon";
?>

<html>
      <head>
<title>Intro to PHP</title>
</head>
<body>
    <h1>
      <!--Basic PHP Code.
      to print variable name's value --!>
      Dear <?php print ($name);?> Welcome to PHP
    </h1>
</body>
</html>

output: 


Question 2,
<?php
      $height = 150;
      $width = 30;
?>

<html><head><title>Using Variables and Operators</title></head>
<body>
           <h2> The output of the code: </h2><br>
           <?php
                $luas = $height * $width;
                print ("Luas segi empat dengan panjang $height dan lebar $width ialah $luas");
           ?>
</body>
</html>

output: 



To modify above code so that can compute and display net salary based on information give.
<?php
      $salary = 2100;
      $allowances = 1000;
 $socso = 210;
?>

<html><head><title>Using Variables and Operators</title></head>
<body>
           <h2> The output of the net salary: </h2><br>
           <?php
                $net = $salary + $allowances - $socso;
                print ("Net Salary is $net");
           ?>
</body>
</html>

output: 

Question3.
<html>

<head><title>Table</title></head>

<body>
      <h1>The output of the code: </h1><br>

<TABLE BORDER = "1">
<?php
            for($row = 1; $row<=3; $row++)
            {
print ("<TR>");//create row
for ($column =1; $column <=2; $column++)
{
         print("<TD>"); //create column
         print("Baris $row, Lajur $column");
              print("</TD>");
             }
             print ("</TR>");
            }
          ?>
</TABLE>

</body>
</html>

output: 


Question 4.

Correct the code that have error in code.

a).
<html>
<head><title>Syntax</title></head>
<body>
      <h1> The output of the code: </h1><br />
   <?php
         for ($a=1;$a<10;$a++)
         {
      echo $a,"\n";
         }
         ?>
</body>
</html>


b).
<html>
<head><title>Syntax</title></head>
<body>
       <h1> The output of the code: </h1><br />
  Welcome <?php echo $_POST["name"];?><br>
       You are <?php echo $_POST ["age"];?>years old
</body>
</html>