PHP / MySQL/ APACHE

 

Download PHP, MySQL, and Apache (if it's not already on your computer)

1. go to http://www.mysql.com/downloads/mysql-3.23.html

2. choose each selection under Linux x86 RPM downloads

3. skip the survey and select html from first mirror listed

4. go to www.smashie.co.uk/tech-docs/linux/installapache-php-sql.htm

5. download php 4.2.3 and apache 1.3.2

6. type on command line to unzip the apache download:

gunzip filename

tar -xvf filename

Install MySQL

type:

rpm -i MySQL-serverFileName

rpm -i MySQL-clientFileName

rpm -i MySQL-sharedFileName

rpm -i MySQL-developFileName

rpm -i MySQL-benchFileName

Install/Configure Apache

1. type:

./configure --prefix=/usr/local/www

make

make install

Install/Configure PHP with Apache

cd php-4.2.3

httpd -l

./configure --withmysql --with-apache = ../apache_1.3.27

make

make install

cd ../apache_1.3.27

./configure

./configure --prefix = /usr/local/www --activate -module=src/modules/php4/libphp4/a

make

make install

2.

cd /usr/local/www/conf

edit /usr/local/www/conf/httpd.conf

Add Type application/x-httpd-php.php

3. go to hosts.allow and add:

in.httpd: 152.97., .sewanee.edu

 

Now that you have MySQL, Apache, and PHP running let's test them!

Set up a Database in MySQL

1. save the following into creat_tables.sql

create table customer
(
customer_id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
title char(4) ,
fname varchar(32) ,
lname varchar(32) NOT NULL,
addressline varchar(64) ,
town varchar(32) ,
zipcode char(10) NOT NULL,
phone varchar(16)
);
create table item
(
item_id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
description varchar(64) NOT NULL,
cost_price numeric(7,2) ,
sell_price numeric(7,2)
);

create table orderinfo
(
orderinfo_id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
customer_id integer NOT NULL,
date_placed date NOT NULL,
date_shipped date ,
shipping numeric(7,2)
);
create table stock
(
item_id integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
quantity integer NOT NULL
);create table orderline
(
orderinfo_id integer NOT NULL,
item_id integer NOT NULL,
quantity integer NOT NULL,
PRIMARY KEY(orderinfo_id, item_id)
);
create table barcode
(
barcode_ean char(13) NOT NULL PRIMARY KEY,
item_id integer NOT NULL
);

create table feedback

(

name varchar(64),

email varchar(32),

item_name varchar(32),
comments varchar(70),

how_good varchar(2)

);

2. mysql -u root

3. CREATE DATABASE databaseName;

4. USE databaseName;

5. SOURCE create_tables.sql;

 

 

Now create a webpage that uses PHP and the database you just created!

Enter your username, password, database, computer's name, and web page where the form will be posted. Then save this as feedback.php:

 

<HTML>
<HEAD>
<TITLE>Beginning MySQL Online Store: Feedback Form</TITLE>
</HEAD>
<BODY BGCOLOR = "FFFFFF" TEXT = "000000">
<TABLE WIDTH="100%" BGCOLOR="#ffcb32">
<TR><TD>
<H2>Tell us what you think about our products</H2>
</TD></TR>
</TABLE>
<?php
#source file not kept in the document root for connection
paramters
$username="user";
$hostname="compName.sewanee.edu";
$password="secret";
$dbname="database name";
#connect to the database server
$db_link = mysql_connect("$hostname", "$username",
"$password")
or die ("Could not connect to the server\n");
mysql_select_db("$dbname");
#if we have been asked to add a suggestion to the database
if ($suggestion_submitted == 1) {
#insert the escaped parameters into the database
$sql = sprintf("INSERT INTO feedback

VALUES(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")
4;,
addslashes($customer_name),
addslashes($client_email),
addslashes($item_name),
addslashes($comments), addslashes($how_good));
##print "<p>$sql<p>"; #-- lkd, debug
$result = mysql_query($sql, $db_link);
if (!$result) {
echo "Cannot insert: " . mysql_error($db_link);
}
}
?>
<FORM ACTION = "web page hyperlink" METHOD = "POST">
<INPUT NAME="suggestion_submitted" TYPE="HIDDEN"
VALUE="1">
<BLOCKQUOTE>
<TABLE BORDER = "0">
<TR>
<TH ALIGN = "left">Name:</TH>
<TD><INPUT TYPE = "text" NAME = "customer_name" SIZE =
"35"
MAXLENGTH = "35"></TD>
</TR>
<TR>
<TH ALIGN = "left">Email:</TH>
<TD><INPUT TYPE = "text" NAME = "client_email" SIZE =
"35"
MAXLENGTH = "35"></TD>
</TR>
<TR>
<TH ALIGN = "left">Product:</TH>
<TD>
<SELECT NAME=item_name>
<?php
#get a list of all the items we have for the drop down box
$item_list_result = mysql_query ("select description from
item", $db_link);
while ($list_row = mysql_fetch_array($item_list_result)) {
#surround each option with the necessary html and send it
out
echo "<OPTION>$list_row[0]</OPTION>\n";
}
?>
</SELECT>
</TD>
</TR>
<TR>
<TH ALIGN = "left">Comments</TH>
<TD><TEXTAREA WRAP = "virtual" NAME = "comments" ROWS =
"5"
COLS = "40">
</TEXTAREA></TD>
</TR>
<TR>
<TH ALIGN ="left">How satisfied are you</TH>
<TD>
<INPUT TYPE="radio" NAME="how_good" VALUE="5"
CHECKED>Very</INPUT>
<INPUT TYPE="radio" NAME="how_good" VALUE="4" >A
lot</INPUT>
<INPUT TYPE="radio" NAME="how_good" VALUE="3"
>Somewhat</INPUT>
<INPUT TYPE="radio" NAME="how_good" VALUE="2" >Not
happy</INPUT>
<INPUT TYPE="radio" NAME="how_good" VALUE="1" >Very
unhappy</INPUT>
</TD>
</TR>
</TABLE>
<P>
<CENTER>
<INPUT NAME="submit_feedback" TYPE = "submit" VALUE =
"Submit this information.">
</CENTER>
</BLOCKQUOTE>
</FORM>
<TABLE>
<TR><TD><H3>Here's what our other customers
said:</H3></TD></TR>
</TABLE>
<?php
#get the suggestion data from the feedback table
$suggestion_list_result = mysql_query ("select
name,product,comments from feedback", $db_link);
while ($list_row =
mysql_fetch_array($suggestion_list_result)) {
#wrap the data with html so that it looks nice
echo "
<TABLE BORDER=0 WRAP=256 CELLSPACING=0 CELLPADDING=0
COLS=1 ROWS=2
BGCOLOR='#ffcb32'>
<TR><TD>
<P STYLE='COLOR: #070568; TEXT-DECORATION: none;'>
$list_row[0] said the following about $list_row[1]:
</P>
</TD></TR>
<TR><TD bgcolor='white'>
$list_row[2]
</TD></TR>
</TABLE>";
}
?>
</BODY>
</HTML>