Thursday, 26 May 2016

Week 13

We had discussion on our final individual project regarding the steps to design a website and the functions need to include in our project. Dr Syamsul opened a link to allow us to book for our presentation date. 

For the lab session 
Today is our last class and we had a short online quiz. Below are the questions and answer of my quiz:

1. Which of the following is true in PHP if $x = 4 and $y = 9?

Select one:

 $y >  "9"

 $x % $y >  $y - $x

 $x == 4 Correct
Correct

 none of the answer

2. What will be displayed in a browser when the following PHP code is executed:

<?php
 $variable = 2;
 switch ($variable)
 {
  case 1:
   echo "Hello World";
   break;
  default:
   echo "Hello Robert";
   break;
 }
?>
Select one:
Correct

3. Which operator is used to compare two values.

Select one:
Correct
Correct
 

4. The if statement is used to execute some code only if a specified condition is true.

Select one:
Correct
 

5. What will be displayed in a browser when the following PHP code is executed:

<?php 
   $x = 6;
   $y = 4;
   $sum = $x + $y; //sum = 10
   $ten = "Ten";

   if ($sum >= 10 && $ten == "Ten") {
       $answer = "Correct";
       echo "Your answer is: $answer";
   }
   else {
       $answer = "Incorrect";
       echo "Your answer is: $answer";
   }
?>
Select one:
Correct
 

6. What will be printed?

if ('2' == '02') {   
  echo 'True';
} else {
  echo 'False';
}
Select one:
Correct

7. How do you get information from a form that is submitted using the "get" method?

Select one:
Correct
 

8. When using the POST method, variables are displayed in the URL.

Select one:
Correct  

9. Since PHP is _____________, the source code is freely available on the web, and developers can install and use it without paying licensing fees or investing in expensive hardware or software.

Select one:
Correct
 

10. What will be displayed in a browser when the following PHP code is executed:

<?php 
   if (8 <= 7) {
       echo "Hello World";
   }
   else {
       echo "Hello YouTube";
   }
?>
Select one:
Correct


11. What will be printed by the code below?


<?php

    FUNCTION TEST()
    {
        ECHO "HELLO WORLD!\n";
    }

    test();
?>
Select one:
Correct

12. All the following statements are TRUE when describing form controls, EXCEPT:

Select one:

13. PHP server scripts are surrounded by which delimiters?

Select one:
Correct

14. What is the correct way to create a function in PHP?

Select one:
Correct

15. Which of the following is NOT a valid PHP variable?

Select one:
Correct

16. Which one is the expected output of the following codes?


============================
<html><head></head> 
<body> 
<h4>CSS stands for:</h4> 

<?php 
//print output 
echo '<h4><i>A: Cascading Style Sheet </i></h4>'; 
?> 
</body></html> 
==========================
Select one:

17. In PHP you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings.

Select one:
Correct

18. The built-in PHP function ___________ is used to collect values in a form with method="post"

Select one:
Correct

19. What is the output of this code?


<?php
function apple($apples=4)
{
 $apples=$apples/2;
 return $apples;
}

$apples = 10;
apple($apples);
echo $apples;
?>
Select one:
Correct

20. What is the expected output of the following PHP codes?

<?php 
$dob= "hello"; 
$age=$dob + 15; 
echo "$age"; 
?> 
Select one:
Correct
 
 

21. Other than echo, state the other way of printing a statement in PHP.

Select one:
Correct

22. What is the output of the following?

<?php
function a($number)
{
  return (b($number)*$number);
}
function b($number)
{
  ++$number;
}
echo a(5);
?>
Select one:
Correct

23. What will be displayed in a browser when the following PHP code is executed:


<?php 
   $bookColor = "red";
   $bookName = "The PHP Basics";

   if ($bookColor == "red" && $bookName == "Steve Jobs") {
       echo "You have the wrong book";
   }
   else {
       echo "You might have the right book";
   }
?>
Select one:
Correct

24. Which one of these variables has a legal name?

Select one:
Correct
Correct

25. PHP and JavaScript are the same.    

Select one:
Correct

26. In PHP, both ________ and ________ can be used for strings.

Select one:

27. What is a correct way to add a comment in PHP?

Select one:
Correct

28. What is the output produced by the PHP codes below:

<?php 
$x = 1.5; 
settype ($x, "integer”); 
echo $x; 

?> 
Select one:
Correct

 29. Which statement about PHP functions is correct?

Select one:
Incorrect

30. What would be the output of the following PHP codes?


<?php 
 $languages=array(0 => "Perl", 1 => "PHP"); 
 $search= "PHP"; 
 $limit= count($languages); 

 for ($i=0;$i<$limit;$i++){ 
  echo "<br>Testing for match with $languages[$i]"; 
  if ($search == $languages[$i]) 
  { 
   echo "<br> $search is an approved language"; 
  } 
 } 
?> 
Select one:
Correct
Correct

Saturday, 21 May 2016

Week 12

What is a PHP Session?

When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser.
So, Session variables hold information about one single user, and are available to all pages in one application.

To start a session and to track session variables across user session:  
session_start();

To register a session: 
session_register(variables);

To destroy a session:
session_destroy();


Lab class was cancelled as we were asked to join the event organized on SMMTC week.
 

Saturday, 14 May 2016

Week 11

Lecturer had uploaded a zip file and we were required to connect it to the database. 
We need to add user account

We need to create a new user account.
Tick "Grant all privileges on wildcard name"

Creating a table.
We encountered some problems while connect the files to the database. However, the problem is solved by deleting the semicolon for the php.ini file as shown in  picture below.



Saturday, 7 May 2016

Week 10

We learnt about the Server Side Script which is MySQL. SQL is a standard language for accessing databases.
To build a web site that shows data from a database, you will need:

  • An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
  • To use a server-side scripting language, like PHP or ASP
  • To use SQL to get the data you want
  • To use HTML / CSS
Some of The Most Important SQL Commands:
Data Manipulation Language
  • SELECT - extracts data from a database
  • UPDATE - updates data in a database
  • DELETE - deletes data from a database
  • INSERT INTO - inserts new data into a database
Data Definition Language
  • CREATE TABLE - creates a new table
  • ALTER TABLE - modifies a table
  • DROP TABLE - deletes a table
  • CREATE INDEX - creates an index (search key)
  • DROP INDEX - deletes an index 
Advantages of using database to store web data:
  • faster access
  • better concurrent access
  • easier changes to data and scripts
  • increased security
Accesing MySQL via PHP
  1. Make a connection to the MySQL database server.
  2. Select the database within MySQL that you want to work with.
  3. Issue an SQL statement/ create the query.
  4. If you are issuing a SELECT statement, iterate through the result set and extract each record.


There is no class for the lab session as Thursday is a holiday.