Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

PHP

PHP assigment, Web Application, Spring 2011
by

Himani Patel

on 30 March 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of PHP

PHP By: Kevin, Brandon, John, Ronald, John PHP Overview PHP is a powerful tool for making dynamic and interactive Web pages.

PHP is the most widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. What is PHP? PHP stands for PHP: Hypertext Preprocessor
PHP is a server-side scripting language, like ASP, JavaServer Page
PHP has driver support for 15 different database systems What do you need? If your server does not support PHP, you must install PHP.
Web-Server
Database
Editor
Here is a link to a good tutorial from PHP.net on how to install PHP5:http://www.php.net/manual/en/install.php PHP Syntax A PHP scripting block always starts with <?php and ends with ?>.
A PHP scripting block can be placed anywhere in the document.
With shorthand support enabled you can start a scripting block with <? and end with ?>.
For maximum compatibility, standard form (<?php) should be used rather than the shorthand form.
PHP Syntax is most Similar to Perl and C Hello World!!!
<html>
<body>
<?php
echo "HelloWorld";
?>
</body>
</html>
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.

Two basic statements to output text with PHP: echo and print.
Ex.
echo 'Hello, One plus one equals $result ' ;
print "Hello, One plus one equals $result";
PHP Syntax (Print) Benefits of PHP More Forgiving than most common programming languages
Supports both procedural and object-oriented programming
Variables do not have to be declared
Many predefined Functions PHP Syntax (Include & Require) Include Construct (continues script)
Require Construct (stops script)
Ex.
Include("header.inc");
Require("header.inc"); PHP Syntax (Comments) ini_set('display_errors',1);
error_reporting(E_ALL); Three Ways to Declare Comments
Single line comment can use # or //
Commentblock can be /* Write Something Here */
Concatenation Operator (.) PHP Syntax (Variables) Declare variable using $
Ex. $student;
Can be any number, letters, digits or underscores
Automatically assigns Types Brandon PHP Syntax (Form) Form Method Attribute
Two Types: GET and POST
$_GET[]
$_POST[]
Brandon Numeric Array $Name = Array("Orange", "Banana");
OR
$Name[0] ="Orange";
$Name[1] ="Banana"; Associative Array $names = ("Bob"=>15, "Sam"=>5);
OR
$names["Bob"] = 15;
$names["Sam"] = 5; Brandon If..Else 4 different conditional statements
If Statement
If…Else Statement
If…Elseif …Else Statement
Switch Statement
If Statement
if (condition) code to be executed if condition is true;
If…Else
if (condition)
code to be executed if condition is true;
else 
 code to be executed if condition is false;
If…Else
if (condition) 
  code to be executed if condition is true;
elseif (condition)  
code to be executed if condition is true;
else 
  code to be executed if condition is false; If..Else Syntax Loops while Loop
while (condition) 
{code to be executed; }

do...while
do 
{  code to be executed;  }
while (condition); For Loop for (init; condition; increment) 
{  code to be executed;  }
init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop)
condition: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
increment: Mostly used to increment a counter (but can be any code to be executed at the end of the loop) Loop Examples <?php
$i=1;
while($i<=5)  
{  
echo "The number is " . $i . "<br />"; 
$i++;
  }
?>
<?php
$i=1;
do 
 {  
$i++;  
echo "The number is " . $i . "<br />"; 
 }
while ($i<=5);
?> For Loop Example <?php
for ($i=1; $i<=5; $i++) 
{  
echo "The number is " . $i . "<br />"; 
}
?> $_GET The built-in $_GET function is used to collect values from a form sent with method="get".

Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.

Note: This method should not be used when sending passwords or other sensitive information!
$_GET <form action="welcome.php" method=“get">Name: <input type="text" name="fname" />Age: <input type="text" name="age" /><input type="submit" /></form>

http://www.randomwebsite.com/welcome.php?fname=Peter&age=37


Welcome <?php echo $_GET["fname"]; ?>.<br />You are <?php echo $_GET["age"]; ?> years old!
$_POST The built-in $_POST function is used to collect values from a form sent with method="post".
Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. $_POST <form action="welcome.php" method=“post">Name: <input type="text" name="fname" />Age: <input type="text" name="age" /><input type="submit" /></form>


Welcome <?php echo $_POST["fname"]; ?>!<br />You are <?php echo $_POST["age"]; ?> years old.
$_REQUEST The PHP built-in $_REQUEST function contains the contents of both $_GET, $_POST, and $_COOKIE.

The $_REQUEST function can be used to collect form data sent with both the GET and POST methods.

Welcome <?php echo $_REQUEST["fname"]; ?>!<br />
You are <?php echo $_REQUEST["age"]; ?> years old. PHP SESSIONs PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
Sessions work like they do in JSP.
Before you can store user information in your PHP session, you must first start up the session.
Sessions can be destroyed by using the ‘unset’ variable function or destroying the entire session.
SESSION Example <?php
session_start();
// store session data
$_SESSION['views']=1;
?>

<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>
</body>
</html> SESSION Example SESSION Example

<?php
unset($_SESSION['views']);
?>
<?php
session_destroy();
?> PHP & MySQL With php, one uses phpmyadmin to manage mysql databases

Like JSP, you have to create a connection to a database, but you have to close the connection when you are finished

SELECT and INSERT statements themselves are the same, but the syntax is different SELECT Example <?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)  
{
  die ('Could not connect: '.mysql_error()); 
 }
mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))  
{  
echo $row['FirstName'] . " " . $row['LastName'];  
echo "<br />"; 
 }
mysql_close($con);
?> INSERT Example <?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con) 
 { 
 die('Could not connect: ' . mysql_error()); 
 }
mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);
?>
Questions??
Study Material W3Schools.com
php.org
Book Pages 353 to 395 Review!!
Full transcript