Esempio n. 1
0
} else {
    $fbID = "";
}
// creates a new row in locations
// $fbID and $db need to be passed to the function as it does not have access to the outside scope
function insert_new_location($table, $fbID, $db)
{
    $sql = "INSERT INTO " . $table . " (title, description, LatLng, type, added_by) VALUES ('{$_POST['title']}', '{$_POST['description']}', '{$_POST['LatLng']}', '{$_POST['type']}', '{$fbID}')";
    try {
        $results = $db->query($sql);
    } catch (Exception $e) {
        echo "Data could not be inserted into the table " . $table . " " . $e;
        exit;
    }
}
// ¦¦¦ These are the three cases which each submit via the same function into different tables
if ($_POST['who'] == 'just_me') {
    insert_new_location($fbID . "_locations", $fbID, $db);
} else {
    if ($_POST['who'] == 'everyone') {
        // this will insert into the _locations table visible to everyone but not to the user
        insert_new_location("_locations", $fbID, $db);
    } else {
        if ($_POST['who'] == 'everyone_and_me') {
            // this will insert into the _locations table visible to everyone and to the user
            insert_new_location($fbID . "_locations", $fbID, $db);
            insert_new_location("_locations", $fbID, $db);
        }
    }
}
header("Location: /places");
// NOTE!!!
// Assumption: Everything is entered correctly
// Creating a new restaurant
$restaurant = array();
$restaurant[RestaurantID] = $restaurantid;
$restaurant[Name] = $restaurantName;
$restaurant[Type] = $restaurantType;
$restaurant[URL] = $restaurantURL;
$addRestaurant = insert_new_restaurant($restaurant);
if ($addRestaurant) {
    // NOTE!!!
    // Assumption: Everything is entered correctly
    // Creating a new location
    $location = array();
    $location[LocationID] = $_POST['locationid'];
    $location[First_Open_Date] = trim($_POST['First_Open_Date']);
    $location[Manager] = trim($_POST['Manager']);
    $location[Phone_Number] = trim($_POST['Phone_Number']);
    $location[Street_Address] = trim($_POST['Street_Address']);
    $location[Hour_Open] = trim($_POST['Hour_Open']);
    $location[Hour_Close] = trim($_POST['Hour_Close']);
    $location[RestaurantID] = $restaurantid;
    $addLocation = insert_new_location($location);
    if ($addLocation) {
        header("Location: restaurant.php?rID=" . $restaurantid);
        die;
    }
} else {
    echo "An error occurred.\n";
    exit;
}