PHP Lecture 3
PHP Lecture 3
What is MySQL?
MySQL is a database server
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: www.php.net PHP is easy to learn and runs efficiently on the server side
Where to Start?
To get access to a web server with PHP support, you can:
Install Apache (or IIS) on your own server, install PHP, and MySQL Or find a web hosting plan with PHP and MySQL support
<?php $myString = "Hello!"; echo $myString; echo "<h5>I love using PHP!</h5>"; ?>
<?php $my_string = "Hello Bob. My name is: "; $my_number = 4; $my_letter = a; echo $my_string; echo $my_number; echo $my_letter; ?>
<?php $my_string = "Hello Bob. My name is: "; echo "$my_string Bobettta <br />"; echo "Hi, I'm Bob. Who are you? $my_string <br />"; echo "Hi, I'm Bob. Who are you? $my_string Bobetta"; ?>
<?php $my_string = "Hello Bob. My name is: "; echo "$my_string Bobettta <br />"; echo "Hi, I'm Bob. Who are you? $my_string <br />"; echo "Hi, I'm Bob. Who are you? $my_string Bobetta"; ?>
$addition = 2 + 4; $subtraction = 6 - 2; $multiplication = 5 * 3; $division = 15 / 3; $modulus = 5 % 2; echo "Perform addition: 2 + 4 = ".$addition."<br />";
$a_string = "Hello"; $another_string = " Billy"; $new_string = $a_string . $another_string; echo $new_string . "!";
$my_name = "someguy"; if ( $my_name == "someguy" ) { echo "Your name is someguy!<br />"; } echo "Welcome to my homepage!";
$my_name = anotherguy"; if ( $my_name == "someguy" ) { echo "Your name is someguy!<br />"; } echo "Welcome to my homepage!";
$number_three = 3;
if ( $number_three == 3 ) { echo "The if statement evaluated to true"; } else { echo "The if statement evaluated to false"; }
$employee = "Bob";
if($employee == "Ms. Tanner"){ echo "Hello Ma'am"; } elseif($employee == "Bob"){ echo "Good Morning Sir!"; } else { echo "Morning"; }
$destination = "Tokyo"; echo "Traveling to $destination<br />"; switch ($destination){ case "Las Vegas": echo "Bring an extra $500"; break; case "Amsterdam": echo "Bring an open mind"; break; case "Egypt": echo "Bring 15 bottles of PEPSI"; break; case "Tokyo": echo "Bring lots of money"; break; case "Caribbean Islands": echo "Bring a swimsuit"; break; }
$destination = "Tokyo"; echo "Traveling to $destination<br />"; switch ($destination){ case "Las Vegas": echo "Bring an extra $500"; break; case "Amsterdam": echo "Bring an open mind"; break; case "Egypt": echo "Bring 15 bottles of PEPSI"; break; case "Tokyo": echo "Bring lots of money"; break; case "Caribbean Islands": echo "Bring a swimsuit"; break; default: echo LEAVE IT!"; break; }
<html><body> <h4>Art Supply Order Form</h4> <form action="process.php" method="post"> <select name="item"> <option>Paint</option> <option>Brushes</option> <option>Erasers</option> </select> Quantity: <input name="quantity" type="text" /> <input type="submit" /> </form> </body></html>
<html> <body> <?php $quantity = $_POST['quantity']; $item = $_POST['item']; echo "You ordered ". $quantity . " " . $item . ".<br />"; echo "Thank you for ordering from Tizag Art Supplies!"; ?> </body> </html>
<?php function myGreeting($firstName){ echo "Hello there ". $firstName . "!<br />"; } myGreeting("Jack"); myGreeting("Ahmed"); myGreeting("Julie"); myGreeting("Charles");
?>
<?php function myGreeting($firstName, $lastName){ echo "Hello there ". $firstName . "!<br />"; } myGreeting("Jack", "Black"); myGreeting("Ahmed", "Zewail"); myGreeting("Julie", "Roberts"); myGreeting("Charles", "Schwab"); ?>
<?php function mySum($numX, $numY){ $total = $numX + $numY; return $total; } $myNumber = 0; echo "Before the function, myNumber = ". $myNumber ."<br />"; $myNumber = mySum(3, 4); echo "After the function, myNumber = " . $myNumber ."<br />";
?>