|
|
 |
MySQL and PHP |
 |
To merely
display the information in your database without the use of a form to call a php script you simply
create your HTML document as you would any other web page but instead of the extension of .htm or .html
you need to name the file with the extension .php. Then within the document itself the section
that you'd like to be the PHP code, you begin it with <? and end it with ?>. For instance:
<P>These are the products I sell:</P>
<TABLE BORDER="1">
<?
mysql_connect("localhost", username, password);
$result = mysql(mydatabase, "select * from products");
$num = mysql_numrows($result);
$i = 0;
while($i < $num) {
echo "<TR>n";
echo "<TD>n";
echo mysql_result($result,$i,"prodid");
echo "</TD>n<TD>";
echo mysql_result($result,$i,"name");
echo "</TD>n<TD>";
echo mysql_result($result,$i,"price");
echo "</TD>n";
echo "</TR>n";
$i++;}
?>
</TABLE>
Thus having the loop in the php program create a table with the products listed. NOTE your username and
password for the database are not written in the file when it's displayed on the Internet so users
viewing the source of your webpage will not see your password.
When using a CGI script to pull information from a form which has been submitted by a browser you must
have the first line of the script have this command on it (Much like perl scripts):
#!/usr/local/bin/phpMySQL/PHP - two great
tutorials:
PHP/MySQL Tutorial Overview
http://hotwired.lycos.com/webmonkey/
programming/php/tutorials/tutorial4.html
Open source has brought a lot more than Linux to the computing world. It has also given us PHP and
MySQL. According to this Webmonkey tutorial, PHP and MySQL are the world's best combination for
creating data-driven sites. In the first installment of this three-lesson tutorial, he covers
everything you need to know to begin developing database hubs. He gives instructions for installation
on both Unix and Windows, and then goes on to show some simple scripts that will insert information
into a database and display that data on a Web page.
Building a Database-Driven Web Site Using PHP and MySQL
http://www.webmasterbase.com/article.php?aid=228
In this 10-part weekly series of articles, the author provides a hands-on look at what's involved in
building a database-driven Web site using the PHP scripting language and the MySQL relational database.
|
|
|