The first page is at the top of the post. There are two pages that it need and here you go.
config.php
<?php
include_once("functions.php");
session_register("login");
session_register("password");
session_register("loggedIn");
$messages=array();
$dbhost="";
$dbuser="";
$dbpass="";
$dbname="";
connectToDB();
?>
And here is the functions page:
[/code]
<?php
function connectToDB() {
global $link, $dbhost, $dbuser, $dbpass, $dbname;
($link = mysql_pconnect("$dbhost", "$dbuser", "$dbpass")) || die("Couldn't connect to MySQL");
mysql_select_db("$dbname", $link) || die("Couldn't open db: $dbname. Error if any was: ".mysql_error() );
}
function newUser($login, $password) {
global $link;
$query="INSERT INTO callers (login, password) VALUES('$login', '$password')";
$result=mysql_query($query, $link) or die("Died inserting login info into db. Error returned if any: ".mysql_error());
return true;
}
function displayErrors($messages) {
print("<b>There were problems with the previous action. Following is a list of the error messages generated:</b>\n<ul>\n");
foreach($messages as $msg){
print("<li>$msg</li>\n");
}
print("</ul>\n");
}
function checkLoggedIn($status){
switch($status){
case "yes":
if(!$_SESSION["loggedIn"]){
header("Location: login.php");
exit;
}
break;
case "no":
if($_SESSION["loggedIn"]){
header("Location: selectdealer.php?".session_name()."=".session_id());
}
break;
}
return true;
}
function checkPass($login, $password) {
global $link;
$query="SELECT login, password FROM callers WHERE login='$login' and password='$password'";
$result=mysql_query($query, $link)
or die("checkPass fatal error: ".mysql_error());
if(mysql_num_rows($result)==1) {
$row=mysql_fetch_array($result);
return $row;
}
return false;
}
function cleanMemberSession($login, $password) {
$_SESSION["login"]=$login;
$_SESSION["password"]=$password;
$_SESSION["loggedIn"]=true;
}
function flushMemberSession() {
unset($_SESSION["login"]);
unset($_SESSION["password"]);
unset($_SESSION["loggedIn"]);
session_destroy();
return true;
}
function doCSS() {
?>
<style type="text/css">
body{font-family: Arial, Helvetica; font-size: 10pt}
h1{font-size: 12pt}
</style>
<?php
}
function field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1) {
global $messages;
if(!$field_data && !$field_required){ return; }
$field_ok=false;
$email_regexp="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|";
$email_regexp.="(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
$data_types=array(
"email"=>$email_regexp,
"digit"=>"^[0-9]$",
"number"=>"^[0-9]+$",
"alpha"=>"^[a-zA-Z]+$",
"alpha_space"=>"^[a-zA-Z ]+$",
"alphanumeric"=>"^[a-zA-Z0-9]+$",
"alphanumeric_space"=>"^[a-zA-Z0-9 ]+$",
"string"=>""
);
if ($field_required && empty($field_data)) {
$messages[] = "$field_descr is a required field.";
return;
}
if ($field_type == "string") {
$field_ok = true;
} else {
$field_ok = ereg($data_types[$field_type], $field_data);
}
if (!$field_ok) {
$messages[] = "Please enter a valid $field_descr.";
return;
}
if ($field_ok && $min_length) {
if (strlen($field_data) < $min_length) {
$messages[] = "$field_descr is invalid, it should be at least $min_length character(s).";
return;
}
}
if ($field_ok && $max_length) {
if (strlen($field_data) > $max_length) {
$messages[] = "$field_descr is invalid, it should be less than $max_length characters.";
return;
}
}
}
?>
[/code]
Like I had said before I cut copied and pasted this together from tutorials.