Example #1
0
function BuildDBandTables($db)
{
    $con = OpenServerConnection();
    // create the database
    if (!mysql_query("CREATE DATABASE IF NOT EXISTS {$db}", $con)) {
        echo "Error creating database: " . mysql_error();
    }
    // create each table
    $result = mysql_select_db($db, $con);
    if (!$result) {
        die('Cannot connect to DB: ' . mysql_error());
    }
    $emp = "CREATE TABLE IF NOT EXISTS employees\n    (\n      id int(11) NOT NULL AUTO_INCREMENT,\n      first_name varchar(100),\n      last_name varchar(100),\n      time_added date,\n      time_deleted date,\n      PRIMARY KEY(id)\n    )";
    $proj = "CREATE TABLE IF NOT EXISTS projects\n    (\n      id int(11) NOT NULL AUTO_INCREMENT,\n      project_name varchar(100),\n      client_id int(11),\n      current_status varchar(100),\n      time_added date,\n      time_deleted date,\n      PRIMARY KEY(id)\n    )";
    $hours = "CREATE TABLE IF NOT EXISTS hours\n    (\n      id int(11) NOT NULL AUTO_INCREMENT,\n      employee_id int(11),\n      project_id int(11),\n      task_date date,\n      num_hours float(11,2),\n      task_description varchar(255),\n      time_added date,\n      time_deleted date,\n      PRIMARY KEY(id)\n    )";
    $cust = "CREATE TABLE IF NOT EXISTS clients\n    (\n      id int(11) NOT NULL AUTO_INCREMENT,\n      client_name varchar(255),\n      contact_name varchar(255),\n      phone varchar(100),\n      street varchar(255),\n      city varchar(255),\n      state varchar(2),\n      zip char(10),\n      time_added date,\n      time_deleted date,\n      PRIMARY KEY(id)\n    )";
    // execute each query
    mysql_query($emp, $con);
    mysql_query($proj, $con);
    mysql_query($hours, $con);
    mysql_query($cust, $con);
    // close the connection to the server
    mysql_close($con);
}
Example #2
0
<?php

/* ******************************************************
    addClient.php
    Tracks clients and their contact information
    
    Part of the Super Basic Small Business Tracker
    Created by Raquel VĂ©lez
   ****************************************************** */
include "globals.php";
$con = OpenServerConnection();
date_default_timezone_set('America/New_York');
$timeAdded = date('Y-m-d H:i:s');
$client = mysql_real_escape_string($_GET['client']);
$contact = mysql_real_escape_string($_GET['contact']);
$phone = mysql_real_escape_string($_GET['phone']);
$street = mysql_real_escape_string($_GET['street']);
$city = mysql_real_escape_string($_GET['city']);
$state = mysql_real_escape_string($_GET['state']);
$zip = mysql_real_escape_string($_GET['zip']);
mysql_select_db($db_name, $con);
mysql_query("INSERT INTO clients(client_name, contact_name, phone, street, city, state, zip, time_added)\n               VALUES('{$client}', '{$contact}', '{$phone}', '{$street}', '{$city}', '{$state}', '{$zip}', '{$timeAdded}')");
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=start.php">';
mysql_close($con);