1.
Write html code to display the above form
a. Give name for all input boxes and buttons
b. Save the file as "form.php"
2. Write php code to
a. Insert data entered by the user to the table only when register button is clicked
b. Display the content from the table on the screen only when display button is clicked.
c. Update student's name using its id, use the same form to do and only when update is
clicked.
d. Delete a student record using ID. Use same form and only when delete is clicked.
All codes should be on a single file called "form.php"
Use database name REGISTRATION and table name STUDENT.
**************************************************************************
What will be the output of the following php code?
1. <?php
2. $num = "1";
3. $num1 = "2";
4. print $num+$num1;
5. ?>
a) 3
b) 1+2
C) Error
d) 12
What will be the output of the following PHP code?
1. <?php
2. $total = "25 students";
3. $more = 10;
4. $total = $total + $more;
5. echo "$total";
6. ?>
a) Error
b) 35 students
c) 35
d) 25 students
View Answer
Answer: c
Explanation:The integer value at the beginning of the original $total string is used in the
calculation. However if it begins with anything but a numerical value, the value will be 0.
Which of the below statements is equivalent to $add += $add ?
a) $add = $add
b) $add = $add +$add
C) $add = $add + 1
d) $add = $add + $add + 1
View Answer
Answer: b
Explanation: a += b is an addition assignment whose outcome is a = a + b. Same can be done
with subtraction,multiplication,division etc.
Which statement will output $x on the screen?
a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;
View Answer
Answer: a
Explanation:A backslash is used so that the dollar sign is treated as a normal string character
rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as
escape character.
What will be the output of the following PHP code?
1. <?php
2. $a = "clue";
3. $a .= "get";
4. echo "$a";
5. ?>
a) get
b) true
c) false
d) clueget
View Answer
Answer: d
Explanation: .= is a concatenation-assignment. $a equals its current value concatenated with
“get”.
What will be the output of the following PHP code?
1. <?php
2. $a = 5;
3. $b = 5;
4. echo ($a === $b);
5. ?>
a) 5 === 5
b) Error
c) 1
d) False
View Answer
Answer: c
Explanation: === operator returns 1 if $a and $b are equivalent and $a and $b have the same
type.
Which of the below symbols is a newline character?
a) \r
b) \n
c) /n
d) /r
View Answer
Answer: b
Explanation:PHP treats \n as newline character.
What will be the output of the following PHP code?
1. <?php
2. echo 'can i go there? \n no i cant.';
3. ?>
a) can i go there? \n no i cant.
b) can i go there?
no i cant.
c) can i go there? no i cant.
d) none
View Answer
Answer: a
Explanation: When a string is enclosed within single quotes both variables and escape sequences
will not be interpreted when the string is parsed.
What will be the output of the following PHP code?
1. <?php
2. $team = "arsenal";
3. switch ($team) {
4. case "manu":
5. echo "I love man u";
6. case "arsenal":
7. echo "I love arsenal";
8. case "manc":
9. echo "I love manc"; }
10. ?>
a) I love arsenal
b) Error
c) I love arsenalI love manc
d) I love arsenalI love mancI love manu
View Answer
Answer: c
Explanation:If a break statement isn’t present, all subsequent case blocks will execute until a
break statement is located.
What will be the output of the following PHP code?
1. <?php
2. $user = array("Ashley", "Bale", "Shrek", "Blank");
3. for ($x=0; $x < count($user); $x++) {
4. if ($user[$x] == "Shrek") continue;
5. printf ($user[$x]);
6. }
7. ?>
a) AshleyBale
b) AshleyBaleBlank
c) ShrekBlank
d) Shrek
View Answer
Answer: b
Explanation: The continue statement causes execution of the current loop iteration to end and
commence at the beginning of the next iteration.
8. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
a) 12
b) 1
c) Error
d) 5
View Answer
Answer: d
Explanation: ?: is known as ternary operator. If condition is true then the part just after the ? is
executed else the part after : .
Which one of the following is the very first task executed by a session enabled page?
a) Delete the previous session
b) Start a new session
c) Check whether a valid session exists
d) Handle the session
View Answer
Answer: c
Explanation:None.
Which directive determines how the session information will be stored?
a) save_data
b) session.save
c) session.save_data
d) session.save_handler
View Answer
Answer: d
Explanation:Its prototype follows: session.save_handler = files|mm|sqlite|user.
What is the default number of seconds that cached session pages are made available before the
new pages are created?
a) 360
b) 180
c) 3600
d) 1800
View Answer
Answer: b
Explanation:The directive which determines this is session.cache_expire.
Which one of the following function is used to start a session?
a) start_session()
b) session_start()
c) session_begin()
d) begin_session()
View Answer
Answer: b
Explanation:None
PHP’s numerically indexed array begin with position __.
a) 1
b) 2
c) 0
d) -1
View Answer
Answer: c
Explanation: Like many programming languages, the first element of an array has an index value
of 0.
2. Which of the following are correct ways of creating an array?
i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);
a) iii) and iv)
b) ii) and iii)
c) Only i)
d) ii), iii) and iv)
View Answer
Answer: a
Explanation:A variable name should start with $ symbol which is not present in i) and you need
not put the square brackets when you use the array() constructor.
7. What will be the output of the following PHP code?
1. <?php
2. $fruits = array ("apple", "orange", "banana");
3. echo (next($fruits));
4. echo (next($fruits));
5. ?>
a) orangebanana
b) appleorange
c) orangeorange
d) appleapple
View Answer
Answer: a
Explanation: The next() function returns the array value residing at the position immediately
following that of the current array pointer.
10. Which function returns an array consisting of associative key/value pairs?
a) count()
b) array_count()
c) array_count_values()
d) count_values()
View Answer
Answer: c
Explanation:None
What will be the output of the following PHP code ?
1. <?php
2. $x = 5;
3. $y = 10;
4. $z = "$x + $y";
5. echo "$z";
6. ?>
a) 15
b) 10 + 5
c) $z
d) $x + $y
View Answer
Answer: b
Explanation: Variable z will store 10 + 5 because 10 + 5 is given in double-quotes.
What will be the output of the following PHP code ?
1. <?php
2. $x = 4;
3. $y = 3;
4. $z = 1;
5. echo "$x = $x + $y + $z";
6. ?>
a) 4 = 4 + 3 + 1
b) 8
c) 8 = 4 + 3 +1
d) Error
View Answer
Answer: a
Explanation: Again since the variables are inside double quotes we get this result.
What will be the output of the following PHP code ?
1. <?php
2. $x = 4;
3. $y = 3
4. $z = 1;
5. $z = $z + $x + $y;
6. echo "$z";
7. ?>
a) $z
b) 15
c) 8
d) 1
View Answer
Answer: c
Explanation: Normal addition of variables x, y and z occurs and result of 8 will be displayed.
What will be the output of the following PHP code ?
1. <?php
2. $x = 3.3;
3. $y = 2;
4. echo $x % $y;
5. ?>
a) 0
b) 1
c) 2
d) Error
View Answer
Answer: b
Explanation: % is the modulo operator. Unlike in C we can use it get reminder or floating point
numbers in PHP.
What will be the output of the following PHP code ?
1. <?php
2. $x = 10;
3. $y = 4;
4. $z = 3;
5. echo $x % $y % $z;
6. ?>
a) 0
b) 1
c) 2
d) Error
View Answer
Answer: c
Explanation: The expression is considered as ($x%$y)%z in this case (10%4)%3 which is 2.
What will be the output of the following PHP code ?
1. <?php
2. $x = 10;
3. $y = 4;
4. $z = 3;
5. echo ($x % ($y) + $z);
6. ?>
a) 5
b) 3
c) 0
d) 1
View Answer
Answer: a
Explanation: The inner most bracket is evaluated first, since it covers only variable y it is as good
as not using brackets.
What will be the output of the following PHP code ?
1. <?php
2. $x = 30;
3. $y = 20;
4. $z = 10;
5. echo $x + $y - $z / ($z - $y);
6. ?>
a) 41
b) -4
c) -5
d) 51
View Answer
Answer: d
Explanation: First ($z – $y) is evalulated then -$z/($z – $y) is evaluated this results in 1 which is
added to $x + $y therefore we get 51.
What will be the output of the following PHP code ?
1. <?php
2. $x = -1;
3. $y = 1;
4. $z = $x * $y + $z;
5. echo $z;
6. ?>
a) Undefined variable z
b) -1
c) Undefined variable z
-1
d) None of the above
View Answer
Answer: c
Explanation: Since the variable z is not defined it returns the error also it takes z as 0 and returns
the value -1.
What will be the output of the following PHP code ?
1. <?php
2. $x = 4;
3. $y = -3;
4. $z = 11;
5. echo 4 + $y * $z / $x;
6. ?>
a) 4.25
b) 3.25
c) -3.25
d) -4.25
View Answer
Answer: d
Explanation: First the * is evaluated then / followed by + therefore we can rewrite this expression
as 4 +((- 3 * 11) / 4) which results in -4.25.
What will be the output of the following PHP code ?
1. <?php
2. $x = 3.5;
3. $y = 2;
4. $z = 2;
5. echo $x / $y / $z;
6. ?>
a) 1.75
b) 0.875
c) 3.5
d) Error
View Answer
Answer: b
Explanation: First $x / $y is evaluated then this is divided by $z therefore we get 0.875