Low cost ecommerce web development India flash website design

User Interaction and Forms


For many applications of PHP, the ability to interact with users who view the
Web page is essential. Veterans of JavaScript tend to think in terms of event
handlers, which let you react directly to the actions of the user — for example,
the movement of the mouse over a link on the page. Server-side scripting languages
such as PHP have a more limited scope when it comes to user interaction. As
PHP code is activated when a page is requested from the server, user interaction
can occur only in a back-and-forth fashion: the user sends requests to the server,
and the server replies with dynamically generated pages.
The key to creating interactivity with PHP is to understand the techniques we
can use to send information about a user's interaction along with his or her request
for a new Web page. PHP makes this fairly easy, as we'll now see.
The simplest method we can use to send information along with a page request
uses the URL query string. If you've ever seen a URL with a question mark following
the file name, you've witnessed this technique in use. Let's look at an easy
example. Create a regular HTML file called welcome1.html (no .php file extension
is required, since there will be no PHP code in this file) and insert this link:
<a href="welcome1.php?name=Kevin">Hi, I'm Kevin!</a>
This is a link to a file called welcome1.php, but as well as linking to the file, we're
also passing a variable along with the page request. The variable is passed as part
of the query string, which is the portion of the URL that follows the question
mark. The variable is called name and its value is Kevin. To restate, we have created
a link that loads welcome1.php, and informs the PHP code contained in the
file that name equals Kevin.
55
User Interaction and Forms
To really understand the results of this process, we need to look at welcome1.php.
Create it as a new HTML file, but this time note the .php extension — this tells
the Web server that it can expect to interpret some PHP code in the file. In the
body of this new file, type:
<?php
$name = $_GET['name'];
echo( "Welcome to our Website, $name!" );
?>

website designer freelance ASP PHP ecommerce web developer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110