Guide to PHP and MySQL (University at Buffalo Version)
Chapter 1: Introduction to PHP
PHP is a popular general-purpose scripting language that is especially suited to web development. (See php.net). PHP code runs on a web server unlike HTML or JavaScript which are handled by a web browser.
PHP code can be embedded in an HTML file usg the <?php
and ?>
tags.
Hello World!
Most beginning programmers start with the standard "Hello World" code:
An HTML/PHP Hello World Web Page
<html>
<head>
<title>The name of this page</title>
<head>
<body>
<h2>Hello!</h2>
<p><?php echo("Hello World!"); ?></p>
</body>
</html>
helloworld.php
The rendered web page would look like this:
Hello!
Hello World!
PHP Comments
PHP provides a few different way to add comments to your code. You can use multi-line comments or inline (single line) comments or PHPDoc comments. Comments should be used to explain what your code is doing. Comments should be used to provide a description of each function including whether there are parameters and whther the function returns a value or not.
/* Assignment: Form Web Page
Author: Your Name Here
Date: Month Day, Year file was last edited
Editor: Notepad++ or TextWrangler or whatever editor you used
*/
$i = 0; // Declare a variable named i to be used in a for loop and assign it a value of zero (0)
/**
* PHPDoc Commments
* This function does something
* @param none
* @return none
*/
function someName() {
// some code
}
?>
Using download.php
Save this file (download.php) to your cda216 web space. Then in your HTML code use this line:
<a href="download.php?file=vars.php">vars.php</a><br/ >
download.php
Test to make sure it works for you.