PHP

nostalgicisolatedSoftware and s/w Development

Nov 4, 2013 (3 years and 10 months ago)

67 views

PHP


PHP is a powerful server
-
side scripting language for creating
dynamic and interactive websites.


PHP is the widely
-
used, free, and efficient alternative to
competitors such as Microsoft's ASP. PHP is perfectly suited
for Web development and can be embedded directly into the
HTML code.



The PHP syntax is very similar to Perl and C. PHP is often used
together with Apache (web server) on various operating
systems. It also supports ISAPI and can be used with
Microsoft's IIS on Windows.



A PHP file may contain text, HTML tags and scripts. Scripts in
a PHP file are executed on the server.


Tuesday, November 05, 2013

Dr.kamaran HamaAli

Before you continue you should have a basic
understanding of the following:



HTML / XHTML


Some scripting knowledge

Tuesday, November 05, 2013

Dr.kamaran HamaAli

What is PHP?



PHP stands for
P
HP:
H
ypertext
P
reprocessor


PHP is a server
-
side scripting language, like
ASP


PHP scripts are executed on the server


PHP supports many databases (MySQL,
Informix, Oracle, Sybase, Solid, PostgreSQL,
Generic ODBC, etc.)


PHP is an open source software (OSS)


PHP is free to download and use


Tuesday, November 05, 2013

Dr.kamaran HamaAli

What is a PHP File?



PHP files may contain text, HTML tags and
scripts


PHP files are returned to the browser as plain
HTML




PHP files have a file extension of ".php",
".php3", or ".phtml"


Tuesday, November 05, 2013

Dr.kamaran HamaAli

What is MySQL?



MySQL is a database server


MySQL is ideal for both small and large
applications


MySQL supports standard SQL


MySQL compiles on a number of platforms


MySQL is free to download and use


Tuesday, November 05, 2013

Dr.kamaran HamaAli

PHP + MySQL



PHP combined with MySQL are cross
-
platform
(means that you can develop in Windows and
serve on a Unix platform)


Tuesday, November 05, 2013

Dr.kamaran HamaAli

Why PHP?



PHP runs on different platforms (Windows,
Linux, Unix, etc.)


PHP is compatible with almost all servers used
today (Apache, IIS, etc.)


PHP is FREE to download from the official PHP
resource:


PHP is easy to learn and runs efficiently on the
server side


Tuesday, November 05, 2013

Dr.kamaran HamaAli

Where to Start?



Install an Apache server on a Windows or
Linux machine


Install PHP on a Windows or Linux machine


Install MySQL on a Windows or Linux machine


Tuesday, November 05, 2013

Dr.kamaran HamaAli

Basic PHP Syntax



A PHP scripting block always starts with


<?php

and ends with
?>
.


A PHP scripting block can be placed anywhere in
the document.


On servers with shorthand support enabled you
can start a scripting block with


<? and end with ?>.


However, for maximum compatibility, we
recommend that you use the standard form
(<?php) rather than the shorthand form.


Tuesday, November 05, 2013

Dr.kamaran HamaAli


<?php

?>


<?

?>

<script language=“php”>

</script>





Tuesday, November 05, 2013

Dr.kamaran HamaAli

Each code line in PHP must end with a semicolon. The semicolon is a separator and is
used to distinguish one set of instructions from another.


<html>

<body>

<?php

echo "Hi Student"; /* we have used echo
statement to output the text “Hi Student” */

?>

</body>

</html>

Tuesday, November 05, 2013

Dr.kamaran HamaAli


Echo code line in php must end with
semicolon;


The semicolon is separate and is used to
distinguish on set of instruction from
another…

Tuesday, November 05, 2013

Dr.kamaran HamaAli


There are two basic statements to output text
with PHP:

echo


and

print
.

In the example above we have used the echo

statement to output the text "Hi student".

Tuesday, November 05, 2013

Dr.kamaran HamaAli

Echo Vs print


Use echo:

Echo is it sound cooler is tiny bit shorter, even
that one character can be speedup the code..

I am kamaran and personally use
echo

because:


1) its more powerful


ORCompared to print, echo is more powerful
because:

Php & echo used for print a message print is
method and slow


Tuesday, November 05, 2013

Dr.kamaran HamaAli


NOW you decided( determine ) which one is
better


<?php


Echo ” good morning”;


?>

Or

print

Tuesday, November 05, 2013

Dr.kamaran HamaAli

Echo and Print



What is the difference between "echo" and
"print" in PHP?



echo is constructor and print is function.


echo cannot take arguments but print can take
arguments. ...


Comments in PHP



In PHP, we use // to make a single
-
line
comment

OR


/* and */ to make a large comment block.


Tuesday, November 05, 2013

Dr.kamaran HamaAli


<html>

<body>

<?php

//This is a comment

/*

This is

a comment

block

*/

?>

</body>

</html>


Tuesday, November 05, 2013

Dr.kamaran HamaAli

Non Executing



<?php


//*$firstname=$_GET['firstname'];


//*$lastname = $_GET['lastname'];

//* echo "welcome to my website, $firsname $lastname!";


?>

Calculator.htm

Calculator.php

$_post


<?php


$v1=$_POST['v1'];

$v2=$_POST['v2'];

$a=$_POST['arithmetic'];

require('calculator.html');

switch($a){

case 'add':

echo $v1+$v2;

break;

case 'minus':

echo $v1
-
$v2;

break;

case 'divide':

{if ($v2==0)echo"Cannot divide by zero";

else echo $v1/$v2;

break;}

case 'multiply':

echo $v1*$v2;

break;

}

?>

Calculator.htm

$_post


<html>

<h1><center>Calculator</center></h1>

<form action=
"calculator.php" method="post">

<table align="center">

<th> Choose arithmetic operator<th>Enter the values </th>

<tr><td>+<input type="radio" name="arithmetic" value="add"
checked><td><input type="text" name="v1">

<tr><td>
-

<input type="radio" name="arithmetic"
value="minus"><td><input type="text" name="v2">

<tr><td>/ <input type="radio" name="arithmetic" value="divide">

<tr><td>*<input type="radio" name="arithmetic" value="multiply">

<tr><td><input type="submit" value="Execute" >

</table>

<h3> the Result</h3>

</form>

</html>



<form action=
"welcome1.php"
method="get">

Name: <input type="text" name="fname" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>



<html>

<body>


Welcome <?php echo
$_POST["name"]; ?>.<br />

You are <?php echo $_POST["age"]; ?> years old.


</body>

</html>



What are the differences between GET and POST methods in
form submitting, give the case where we can use GET and we
can use POST



When you want to send short or small data,
not containing ASCII characters, then you can
use GET” Method. But for long data sending,
say more then 100 character you can use
POST method. Once most important
difference is when you are sending the form
with GET method. You can see the output
which you are sending in the address bar.
Whereas if you send the form with POST”
method then user can not see that
information.

Predefined variables:



PHP has several predefined variables called superglobals.


Superglobals are always present and available in any PHP script.

The superglobals are arrays of other variables.



PHP superglobals that work with forms:


1) $_GET contains any variables provided to a script through the GET
method.


2) $_POST contains any variables provided to a script through the POST
method.


3) $_FILES contains any variables provided to a script through file uploads.