Basically I have a file that is plain php and I use the includes function the add the html so that all messages from the php file will be displayed in the html form. The scripts below are the files:
register.php:
<?php
// This is for the registration page
$page_title = 'Welcome to ADesigns: Registration';
include ('includes/header.html');
// Check if the form has been submitted:
if (isset($_POST['submitted']))
{
$errors = array(); // Initialize an error array.
// Check for a first name:
if (empty($_POST['fname']))
{
$errors[] = 'You forgot to enter your first name.';
}
else
{
$fn = trim($_POST['fname']);
}
// Check for a last name:
if (empty($_POST['lname']))
{
$errors[] = 'You forgot to enter your last name.';
}
else
{
$ln = trim($_POST['lname']);
}
// Check for an email address:
if (empty($_POST['email']))
{
$errors[] = 'You forgot to enter your email address.';
}
else
{
$e = trim($_POST['email']);
}
// Check for a category:
$categoryValues = array('Men', 'Women', 'Kids', 'Unisex', 'Accessories', 'Shoes');
$category = ''; //start empty
//do the check here:
if(isset($_REQUEST['category']))
{
if (in_array($_POST['category'], $categoryValues)) {
$category = trim($_POST['category'] );
}
else{
$errors[] = "You forgot to select a category.";
}
}
else
{
$errors[] = "You forgot to select a category.";
}
// Check for membership type:
if (isset($_POST['membership']))
{
$membership = $_POST['membership'];
if ($membership = 'designer')
{
$membership = trim($_POST['membership']);
}
else if ($membership = 'visitor')
{
$membership = trim($_POST['membership']);
}
}
else
{
$errors[] = "You forgot to select a membership.";
}
// Check for a loaction:
if (empty($_POST['location']))
{
$errors[] = 'You forgot to enter your location.';
}
else
{
$l = trim($_POST['location']);
}
// Check for an username:
if (empty($_POST['username']))
{
$errors[] = 'You forgot to enter your username.';
}
else
{
$u = trim($_POST['username']);
}
// Check for a password and match against the confirmed password:
if (!empty($_POST['pass1']))
{
if ($_POST['pass1'] != $_POST['pass2'])
{
$errors[] = 'Your password did not match the confirmed password.';
}
else
{
$p = trim($_POST['pass1']);
}
}
else
{
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors))
{
// If everything's OK.
// Register the user in the database...
require_once ('mysql_connect.php'); // Connect to the db.
// Make the query:
// $q - stands for $query
// $r - stands for $result
$q = "INSERT INTO user (fname, lname, email, category, membership, location, username, password, reg_date ) VALUES ('$fn', '$ln', '$e', '$category', '$membership', '$l', '$u', SHA1('$p'), NOW() )";
$r = @mysql_query ($q); // Run the query.
if ($r)
{
// If it ran OK.
// Print a message:
echo '<h1>Thank you!</h1>
<p>You are now registered. Please <a href="login.html">login</a></p>';
}
else
{
// If it did not run OK.
// Public message:
echo '<h1>System Error</h1>
<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
// Debugging message:
echo '<p>' . mysql_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
} // End of if ($r) IF.
mysql_close($dbc); // Close the database connection.
// Include the footer and quit the script:
include ('includes/footer.html');
exit();
}
else
{
// Report the errors.
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg)
{
// Print each error.
echo " - $msg<br />\
";
}
echo '</p><p>Please try again.</p><p><br /></p>';
} // End of if (empty($errors)) IF.
} // End of the main Submit conditional.
?>
<?php
include(‘includes/footer.html’);
?>
header.html:
<?xml version=“1.0” encoding=“utf-8”?>
<!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=utf-8” />
<title><?php echo $page_title; ?></title>
<link href=“css/main.css” rel=“stylesheet” type=“text/css” />
</head>
<body>
<table id=“outerTable”>
<tr><td id=“logo”>
<div>
<img src=“./images/logo.png” width=“150” height=“55” alt=“company_logo” />
</div>
</td></tr>
<tr><td id =“nav”>
<div>
<a href=“home.html”>Home</a> |
<a href=“designers.html”>Participate</a> |
<a href=“aboutUs.html”>About ADesigns</a> |
<a href=“contact.html”>Contact Us</a>
</div>
</td></tr>
<tr><td id=“banner”> <! – page banner image –>
<img src=“images/home.jpg” width=“770” height=“” alt=“welcome to ADesigns”>
</td></tr>
<tr><td>
<table id=“contentTable”>
<tr>
<td id=“topLeft”>
<div id=“welcomeBox”>
<h3>Welcome!!</h3>
<p>This is a final year project of mine that enables young aspiring designers of
any cateegory: cloths, bags, mens wear, womens wear and a host of other types.
You are free to look aroud and comment on designs but should you need more information, you have to register but
not to worry. It is free!!</p>
<p><a href=“enter.html”>Enter/Browse</a></p>
</div> <! – mainContent –>
</td>
<td id=“topRight”>
<div id=“loginRegBox”>
<h3>Join Us</h3>
<p>If you are thinking of showing your designs or connecting with like minded designers,
this is where you should be. Our site hosts a range of youngy asipring designers seeking
to show thier work wide audience. So please what are you waiting for join us now</p>
<p><a href=“login.html”>Login</a> | <a href=“register.html”>Register</a></p>
</div> <! -- mainContentRight -->
</tr>
<tr><br /></tr><tr><br /></tr>
<tr>
<td id="bottomLeft">
<div id="newDesigners">
<br />
<h3>New Designers</h3>
<p>This will show designers that are just registered into the DB.</p>
<ul>
<li><a href="">Designer A</a></li>
<li><a href="">Designer B</a></li>
<li><a href="">Designer C</a></li>
<li><a href="">Designer D</a></li>
<li><a href="">Designer E</a></li>
<li><a href="">Designer F</a></li>
</ul>
</div> <! -- mainContentBottom -->
</td>
<td id="bottomRight">
<div id="weeksDesigners">
<br />
<h3>Designers of the Week</h3>
<p>This should show a list of all designers for the week. Preferably, those that
have registered for that week.</p>
</div> <! -- mainContentBottomRight -->
</tr>
</table>
</td></tr>
</table>