PHP Guide
PHP Guide
b. Save the PHP scripting file in WWW folder inside the Wamp Server (if you are
working with Wamp Server) OR in htdocs folder if you are using Xamp as your Server
c. It is important to note that PHP script is written between the php tag as shown in the next
figure
<?php
?>
3. Save the file in the WWW folder(as we are using Wamp Server)
WWW folder location is chosen
4. Now, open the Browser and type localhost in the address bar, this will open the default
localhost\Test.PHP
we can also use the print statement instead of echo statement to output the
messages as well.
Replace the echo statement with the following print statement, save the file and run
the browser, you will see the same output as echo statement has presented with
you.
print "Aslam-o-Alaikum";
Embedding/Adding the HTML tags inside the echo statement
We can embed all the HTML tags inside the echo statement of PHP. This is shown
in the next Script.
Open the previously saved file , i.e. Test.php, and add some more code in it as
shown
You can see that we have added some HTML tags inside the echo statement. This
demo also shows the usage of print statement discussed above.
Variables in PHP
1. In PHP variables are declared by prefixing their name with dollor sign ($)
4. Open the above saved Test.PHP file and modify its code as shown
echo "Sum=".$sum;
if statement in PHP
if statement in PHP as the same syntax as in C/C++.
if(Condition)
Statement1;
if(Condition)
{
Statement1;
Statement1;
}
Example:
If-else statement in PHP
The Syntax of simple if-else statement in PHP
if(Condition)
Statement1;
else
Statement1;
Example:
The Syntax of simple if-else statement in PHP
if(Condition)
{
Statement1;
Statement2;
}
else
{
Statement1;
Statement2;
}
Example:
Nested if-else statement in PHP
Nested if-else structure Example
Switch statement in PHP
Example:
Loops in PHP
for loop
for loop in PHP as the same syntax as in C/C++.
Example:
Save and run the script. The sample output is shown by:
while loop in PHP
do-while loop in PHP
Example:
Fundamentals/OOP in PHP
Passing Data from HTML to PHP Web Page
Design these two forms
<html>
<body>
<b>Customer Registration </b><br/>
<form action="Test.php" method="Post">
<Table width="100%">
<tr>
<Td width="15%">Name: </td>
<td><input type="text" name="txtCustomerName" /></td>
</tr>
<tr>
<td>Cell# </td>
<td><input type="text" name="txtCustomerCellNo" /></td>
</tr>
<tr>
<Td>Email address: </td>
<td><input type="text" name="txtCustomerEmailAddress" /></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="txtCustomerCity" /></td>
</tr>
<Tr>
<td></td>
<td><input type="Submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<body>
<?php
echo"<b>Customer with following details has been Registered
Successfully................<b /><br />";
echo "Name:".$_POST["txtCustomerName"];
echo"<br/>";
echo "Cell#:".$_POST["txtCustomerCellNo"];
echo"<br/>";
echo "Email:".$_POST["txtCustomerEmailAddress"];
echo"<br/>";
echo "City:".$_POST["txtCustomerCity"];
?>
</body>
</html>
Run the HTML
http://localhost/CustomerRegistraiton.html
Fill in the form, press the Submit button
CS-709
Instructions: Attempt all Questions. Attempt MCQs on Question paper and return the
same in First 20 Minutes.
1. Cookies are always stored on Server to keep the track of Web User activities.
[True/False]
2. We can use foreach loop to find the Maximum number from one dimensional Array
[True/False]
3. We can design dynamic and responsive web sites using HTML [True/False]
4. Internal CSS once designed in one web page, can be used in all other web pages of web
site. [True/False]
5. In PHP, string variable is declared using the following special syntax: [True/False]
String $strVar = “Hello! This is a String Variable in PHP”;
Question N0. 2 Suppose there is a MySQL database named MyDatabase, the name of database
server is DatabaseServer, User Name for the database server Abdullah and Password is
“Farooqxy%”. There is one table named tbl_Projects (ProjectSID, ProjectTitle,
ProjectSupervisor,CellNo,Email). You are required to design a HTML page to get the value for
each of these attributes. Then finally post the data to next page and store the input data to
database. Also, confirm Project Title should not be NULL, Email must be correct. [Marks : 08]
Question N0. 4 Briefly describe each of the following by providing appropriate programming
examples
a. Design a PHP function that returns the maximum of two Numbers. Numbers must be
passed to function.
b. Differentiate between alert() & document.write() functions in JavaScript.
c. Write a simple PHP code to shown how concatenation between string and number
variable is done in PHP.
d. Differentiate between Inline CSS & Internal CSS. Give Examples.
e. Differentiate between GET & POST methods used for FORM data submission.
[Marks : 10]
Question N0. 3 Why Associative array is used in PHP? Suppose following data is stored in an
Associative array named Sales. Following data is stored in this array against each item as shown
[Marks : 07]
For example, if user enters 3000 in the textbox and click the button then all the items in the
Associative array with total sale amount greater than 3000 must be displayed on screen.
*****Good Luck*****
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
CS-
Registration No.________________ Total Time:
60 Minutes
Maximum Points: 2
-----------------------------------------------------------------------------------
Instructions:
You are required to display all those patient details in tabular format in PHP page whose Age
is between 20 to 30. Your are also required to not show the Primary key value in the output,
instead you can shown the Serial Number before each patient details.
*****Good Luck*****
------------------------------------------------------------------------------------------
Compiled & Written By
ON
Java, PHP, ASP.Net with C-Sharp, Working With SQL Server, Oracle 10g, Creating Fusion Charts in ASP.Net,
Using Crystal Reports in ASP.Net, FYP Project Ideas, Software Development Latest Jobs
http://www.ASPUiiTBlogSpot.com