Пример #1
0
function addUser($username, $password)
{
    // insert into users
    $query = "insert into `users` (`name`) values (\"{$username}\") ";
    if (preparedStatement($query)) {
        // get new user id
        $userId = getUserId($username);
        // hash password
        // insert into pass
        $query = "insert into `pass` (`user`, `word`) ";
        $query .= "values (" . $userId . ",\"" . $password . "\")";
        // return true or false
        return booleanReturn($query);
    } else {
        // something went wrong
        // delete user name from db?
        return false;
    }
}
Пример #2
0
function updatePosting($user)
{
    $title = $_POST["title"];
    $url = urldecode($_POST["url"]);
    $companyName = $_POST["company"];
    $locationName = $_POST["location"];
    # string value needs to be converted to int
    $source = $_POST["source"];
    $id = $_POST["sid"];
    // if location doesn't exist in locations table yet, add it
    if (locationExists($locationName) != true) {
        addLocation($locationName);
    }
    $locationId = getLocationId($locationName);
    // if location doesn't exist yet for user, add it
    if (companyIdExists($companyName) != true) {
        addCompany($companyName);
    }
    $companyId = getCompanyId($companyName);
    $query = "update postings ";
    $query .= "set title=\"{$title}\", ";
    $query .= "source=\"{$source}\", ";
    $query .= "location={$locationId}, ";
    $query .= "company={$companyId}, ";
    $query .= "url=\"{$url}\" ";
    $query .= "where id = {$id} ";
    //echo $query;
    if (booleanReturn($query)) {
        echo json_encode(true);
    } else {
        echo "failed to add posting";
    }
}