Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Good idea to capture that knowledge but I would recommend putting a section on how to install PHP if not installed already before configuring Apache. (with link to entropy.ch).

Also, maybe add a section how to install virtual hosts in httpd? Or that should be separate article?
 
well, we can address that as well. I think first we should make the guide and assume that they have purchased a hosting plan that supports PHP and MySQL (which is what most people do) and then drill down further into home setup.
 
okay, first page.

Code:
<?php session_start();
$name=$_SESSION['name'];
$email=$_SESSION['email'];
$phone=$_SESSION['phone'];
$office=$_SESSION['office'];
$nickname=$_SESSION['nickname'];

echo "Your name is $name <br>";
echo "Your email is $email <br>";
echo "Your phone is $phone <br>";
echo "Your office is $office <br>";
echo "Your nickname is $nickname <br>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Page 1</title>
</head>
<body>
	<form method="post" action="pg2.php">
		<p>Your name?</p><input type="text" name="name" />
		<p>Your email?</p><input type="text" name="email" />
		<input type="submit" />
	</form>

</body>
</html>
 
page 2

Code:
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Page 3</title>
</head>
<?php 
$_SESSION['name']=$_POST['name'];
$_SESSION['email']=$_POST['email'];

$name=$_SESSION['name'];
$email=$_SESSION['email'];
$phone=$_SESSION['phone'];
$office=$_SESSION['office'];
$nickname=$_SESSION['nickname'];

echo "Your name is $name <br>";
echo "Your email is $email <br>";
echo "Your phone is $phone <br>";
echo "Your office is $office <br>";
echo "Your nickname is $nickname <br>";
?>
<body>
	<form method="post" action="pg3.php">
		<p>Your telephone?</p><Input type="text" name="phone" />
		<p>Your office?</p><input type="text" name="office" />
		<input type="submit" />
	</form>
</body>
</html>
 
page 3

Code:
<?php  session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Page 3</title>
</head>
<?php
$_SESSION['phone']=$_POST['phone'];
$_SESSION['office']=$_POST['office'];

$name=$_SESSION['name'];
$email=$_SESSION['email'];
$phone=$_SESSION['phone'];
$office=$_SESSION['office'];
$nickname=$_SESSION['nickname'];

echo "Your name is $name <br>";
echo "Your email is $email <br>";
echo "Your phone is $phone <br>";
echo "Your office is $office <br>";
echo "Your nickname is $nickname <br>";
?>
<body>
<form method="post" action="pg4.php">
	<p>What is your nickname?</p><input type="text" name="nickname" />
	<input type="submit"  />
</form>

</body>
</html>
 
page 4

Code:
<?php  session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Page 4</title>
</head>
<?php
$_SESSION['nickname']=$_POST['nickname'];

 ?>
<body>
<?php

//output session variables to confirm
$name=$_SESSION['name'];
$email=$_SESSION['email'];
$phone=$_SESSION['phone'];
$office=$_SESSION['office'];
$nickname=$_SESSION['nickname'];

echo "Your name is $name <br>";
echo "Your email is $email <br>";
echo "Your phone is $phone <br>";
echo "Your office is $office <br>";
echo "Your nickname is $nickname <br>";
?>
<form method="post" action="process.php">
If this information is correct, press to submit <br />
<input name="add" type="submit" id="add" value="add" />
</form>

</body>
</html>
 
process page, enters it all into the database

<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Process</title>
</head>
<body>
<?php
if(isset($_POST['add']))
{
//Make Connection
require_once("./include/mysql_connect.php");

//Make Query
$query = "INSERT INTO contacts (name, email, telephone, office, nickname) VALUES ('$name','$email','$phone','$office', '$nickname')";
$result = @mysql_query($query); //run the query

if ($result)
{
//it ran okay
echo '<h1>Thank You!</h1>';
$_SESSION['email']=NULL;
$_SESSION['name']=NULL;
$_SESSION['phone']=NULL;
$_SESSION['office']=NULL;
$_SESSION['nickname']=NULL;
session_unset(); //unsets session variables
session_destroy(); //destorys session
exit();
}
else
{
//it did not run okay
echo '<h1>System Error</h1>You could not be registered due to a system error';
echo '<p>' .mysql_error() . '<br /><br />Query: ' . $query . ' </p>'; //debug message
exit();
}

//close connection
mysql_close();
}
?>
</body>
</html>
 
this is the actual page that is used to create the database connection, from page 4

Code:
<?php # Script - mysql_connect.php

//This file contains the database access information
//This file also establishes a connection to MySQL and selects the database

//Set the database access information as constants
DEFINE ('DB_USER', 'youruser'); //has only write and select privs for security
DEFINE ('DB_PASSWORD', 'yourpassword'); 
DEFINE ('DB_HOST','yourdbhost'); //database URL
DEFINE ('DB_NAME','yourdbname'); //selects the database

//Make the connection
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ('could not make connection to MySQL: ' . mysql_error());

//Select the database
@mysql_select_db(DB_NAME) or die ('Could not select the database: ' . mysql_error());
?>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.