Example #1
0
<?php

require_once '../../common/php/db.php';
$TABLE_NAME = 'sources';
$DB_NAME = 'uedwardn_clips';
# Get a connection to the database
$conn = connect_db($DB_NAME);
# These are the variables expected via POST
$posted_var_names = array('id');
# Get the POST variables
$posted_vars = get_vars($posted_var_names);
# Make an sql insert statement
$sql = get_sql_select_query($conn, $TABLE_NAME, $posted_vars);
# Query the db
$result = mysqli_query($conn, $sql);
if ($err = mysqli_error($conn)) {
    echo '{"success":false, "error":"' . $sql . '"}';
} else {
    echo result2json($result);
}
?>

Example #2
0
    $insert_vars[$key] = $val;
}
# Pick out the first and last name of the first author.  It's used for
# making the bib_code and naming the .pdf
$first_author = $posted_vars['authors'][0];
$last_name = $first_author[0];
$first_name = $first_author[1];
echo var_dump($first_author);
# If the user hasn't set the bib_code, make one from author names and year
if (missing('bib_code')) {
    $bib_code = $posted_vars['pub_date'] . $last_name;
    $bib_code .= time() % 100;
    $insert_vars['bib_code'] = $bib_code;
}
# Validation -- Make sure that the bib_code is unique #
$sql = get_sql_select_query($conn, $TABLE_NAME, array('bib_code' => $bib_code));
$result = mysqli_query($conn, $sql);
if ($err = mysqli_error($conn)) {
    echo '{"success":false, "error":"' . $err . '", "sql":"' . $sql . '"}';
    exit(1);
}
if (mysqli_num_rows($result)) {
    echo '{"success":false, "error":"Ref codes must be unique; ' . $bib_code . ' exists already.", "sql":"' . $sql . '"}';
    exit(2);
}
# Check for a file upload, if so save it. Mark the path in the database
if (is_uploaded_file($_FILES['pdf']['tmp_name'])) {
    $dest_name = $_SERVER['DOCUMENT_ROOT'] . '/snips/pdfs/';
    $first_author = $posted_vars['authors'][0];
    $dest_name .= $first_author[0] . '.' . $first_author[1];
    $dest_name .= '.' . $posted_vars['pub_date'];