home *** CD-ROM | disk | FTP | other *** search
- Code examples from PHP feature
- ------------------------------
-
-
-
- [fig.1]
-
- <html>
- <body>
- <P>This is a test of PHP. If you can't see anything below this line, PHP isn't working properly.</P>
-
- <?php
- echo "PHP is working!";
- phpinfo();
- ?>
-
- </body>
- </html>
-
- [end of fig.1]
-
-
- [fig.2]
-
- <html>
- <body>
- <P>Browser detection.</P>
-
- <?php
- if(strstr($HTTP_USER_AGENT,"MSIE")) {
- ?>
-
- <P>Internet Explorer detected. IE-specific HTML code goes here.</P>
-
- <?
- } else {
- ?>
-
- <P>Some other browser detected. Generic HTML code goes here.</P>
-
- <?
- }
- ?>
-
- </body>
- </html>
-
- [end of fig.2]
-
-
- [fig.3]
-
- <html>
- <body>
- <P>User-submitted variables.</P>
-
- <form action="name.php" method="post">
- Your first name: <input type="text" name="firstname">
- Your surname: <input type="text" name="surname">
- <input type="submit">
- </form>
-
- </body>
- </html>
-
- [end of fig.3]
-
-
- [fig.4]
-
- <P>Welcome. Your first name is <?php echo $firstname; ?>.
- Your surname name is <?php echo $surname; ?>.</P>
-
- [end of fig.4]
-
-
- [fig.5]
-
- <html>
- <body>
- <P>Extracting values from the database.</P>
-
- <!-- The next bit connects to the database (and won't be visible to a browser!) -->
- <!-- Use the same values for localhost, username and password as you did in phpMyAdmin -->
-
- <?php
- $thisdb = mysql_connect("localhost", "username", "password");
- mysql_select_db("test",$thisdb);
- ?>
-
- <!-- Next, use SQL to pick a table - ours is called 'birthdays' -->
-
- <?php
- $sql="SELECT * FROM birthdays";
- $result=mysql_query($sql,$thisdb);
- ?>
-
- <!-- Now extract the first row of that table and put it in an array -->
-
- <?php
- $tablerow = mysql_fetch_array($result);
- ?>
-
- <!-- Finally, extract individual variables from the array and print them -->
-
- <?php
- $counter = $tablerow["counter"];
- $name = $tablerow["name"];
- $birthday = $tablerow["birthday"];?>
-
- echo "Entry number $counter: <B>$name</B>'s birthday is $birthday<BR>";
-
- ?>
-
- </body>
- </html>
-
- [end of fig.5]
-
-