Pages

Monday, May 13, 2013

PHP Syntax: Weird and Wonderful:

You’ve got a couple of PHP programs running, and one of them even works
with an HTML form. But so far, you’ve just been typing code. Even though
you’ve just gotten started with PHP, you’re ready to dig deeper, and start to
understand what’s going on in that code. In this chapter, you’re going to get comfortable
with a lot of the PHP syntax: that means learning what special words you
type into your programs, and what each one of those special words—usually called
keywords—tells PHP to do.
Fortunately, this learning doesn’t mean you can’t still build interesting programs that
run in a web browser. In fact, since almost everything that’s done with PHP involves
Web pages, all your scripts in this chapter will accept information from a Web form
and work with that information. So you’re not just learning PHP; you’re learning to
write Web applications.

Get Information from a Web Form 

In sayHelloWeb.php, you used this line to get the value of a variable called “name”
from the sayHello.html web form:
echo $_REQUEST['name'];
You may remember that $_REQUEST is a special PHP variable that lets you
get information from a web request. You used it to get one particular piece of
information—the user’s name—but it can do a lot more.

Access Request Parameters Directly

 

In fact, to see just how handy $_REQUEST really is, open up your text editor. Type
the code below, in which a visitor enters her name and several other important bits of
contact information, like her Twitter handle, Facebook page URL, and email address.
<html>
<head>
<link href="../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 2-1</div>
<div id="content">
<h1>Join the Missing Manual (Digital) Social Club</h1>
<p>Please enter your online connections below:</p>
<form action="scripts/getFormInfo.php" method="POST">
<fieldset>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" size="20" /><br />
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" size="20" /><br />
<label for="email">E-Mail Address:</label>
<input type="text" name="email" size="50" /><br />
<label for="facebook_url">Facebook URL:</label>
<input type="text" name="facebook_url" size="50" /><br />
<label for="twitter_handle">Twitter Handle:</label>
<input type="text" name="twitter_handle" size="20" /><br />
</fieldset>
<br />
<fieldset class="center">
<input type="submit" value="Join the Club" />
<input type="reset" value="Clear and Restart" />
</fieldset>
</form>
</div>
<div id="footer"></div>
</body>
</html>

GOOGLE FUN

Google is very nice...... You Know here?
Click This link: http://www.google.com.hk/intl/zh-CN/landing/shuixia/



Sunday, May 12, 2013

Upload Your HTML, CSS, and PHP:

When you’re running a PHP program on your own machine, using the command
line, as soon as you’ve saved your PHP you can run it. But when you’re working with
web pages and web applications, things are a bit trickier.
When you’re building a web page, you have to upload your HTML, CSS, and any
JavaScript you’ve written to your own web server. Then, you access those files with
a browser, through a web address like www.yellowtagmedia.com/sayHello.html.
Typing that web address into your browser causes your server to supply your HTML
to whatever web browser requested the page.
PHP works the same way. Once you’ve written your PHP programs, you upload
them onto your web server with your HTML and CSS. Typically, you’ll end up with
files and directories like the following:
• Root or home directory (/). Your web root, where you put all your HTML. This
usually is the location referenced by a URL like yellowtagmedia.com/, without
any specific file after the web server name.
• CSS directory (css/). The directory where all your site’s CSS is stored.
• JavaScript directory (js/). Your JavaScript files go here. You’ll often see this
directory also called scripts/, but since PHP programs are also called scripts,
it’s a good idea to be more explicit in your naming.
• PHP directory (scripts/). Here’s where you put all your PHP programs. Again,
you could call this something more specific like php/ or phpScripts/, but more
often than not, websites use scripts/ for this directory, so following that lead
is a good habit to get into.
• Examples directory (ch01/, ch02/, and so forth). As you’re working through
the examples, you’re going to end up with a lot of PHP programs, and fast.
To keep everything organized, you should have a separate directory for each
chapter. So when you upload sayHello.html and sayHelloWeb.php, upload them
into ch01/sayHello.html and ch01/scripts/sayHelloWeb.php.

Write a PHP Script:

Now that you’ve got an HTML page sending information to sayHelloWeb.php, you
need to actually write that code. When you write PHP to run on the Web, it’s not
much different from the program you’ve already written (page 14). You have to get
information a little differently, because there’s no command line that a user can type
into. But other than that, things stay pretty much the same.
Open up a new text editor and type the PHP code shown here; it should look sort
of like an HTML-ized version of the sayHello.php program:
<html>
<head>
<link href="../../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 1-1</div>
<div id="content">
<h1>Hello, <?php echo $_REQUEST['name']; ?></h1>
<p>Great to meet you. Welcome to the beginning of your PHP programming
odyssey.</p>
</form>
</div>
<div id="footer"></div>
</body>
</html>
Save this program as sayHelloWeb.php, and be sure you’ve got your file in plain
text with the right extension.
The first thing you probably noticed here is that this file looks a whole lot like HTML.
In fact, compared to sayHello.php, the first PHP program you wrote, this version
might look like a style of programming that’s a lot easier to learn. That’s because
once you’re using PHP to work and interact with web pages, a lot of what your PHP
programs will do is insert data into existing web pages, which means you’ll be working
with HTML a lot. Of course, that’s great news, because you already know HTML,
so you’ll be adding to what you know, rather than learning something completely
new from scratch.
Once you realize that a lot of this program is just HTML, you can probably already
guess what a lot of this program does. Here’s a section-by-section breakdown:
• The page starts out with a normal html element and head section.
• The body section begins, and sets up the page heading and example number,
just like the regular HTML page, sayHello.html.
• The page defines a heading with h1, and prints “Hello,.“
• The <?php tells the browser some PHP code is coming. Then, then $_REQUEST
variable is accessed, and a property called name within that variable is printed
using echo.
• The end of the PHP code is indicated with ?>.
• The rest of the HTML is output, just as in sayHello.html.
This program, like most PHP programs you’ll write, accepts its input from a web
page, either from one built in HTML like the pages you’ve created before, or from
another PHP program. It’s the job of that web page—sayHello.html in your case—to
get the user to enter her information, and then send that information on to this
program. The information from that HTML page is stored in $_REQUEST, which is a special variable in PHP.

Writing Your Second Program:

Start with an HTML Page


To get started, open up a new document in your text editor or favorite HTML editor,
and create this HTML page:
<html>
<head>
<link href="../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 1-1</div>
<div id="content">
<h1>Welcome!</h1>
<p>Hello there. So I hear you're learning to be a PHP programmer!</p>
<p>Why don't you type in your name for me:</p>
<form action="scripts/sayHelloWeb.php" method="POST">
<p>
<i>Enter your name:</i> <input type="text" name="name" size="20" />
</p>
<p><input type="submit" value="Say Hello" /></p>
</form>
</div>
<div id="footer"></div>
</body>
</html>

Website Programing: This program does just a few simple things:

Website Programing: This program does just a few simple things: