Created
September 26, 2012 13:15
-
-
Save mebrett/3787964 to your computer and use it in GitHub Desktop.
code for form for adding new documents to Maury database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title>Maury Database: Add Document</title> | |
</head> | |
<body> | |
<h2>Add new documents to Maury database</h2> | |
<form method="post" action="insert_doc.php"> | |
<?php | |
$con = mysql_connect('server', 'user', 'password'); | |
$maury2 = mysql_select_db('maury2', $con); | |
if (!$maury2){ | |
die (mysql_error()); | |
} | |
?> | |
<!-- Add document date --!> | |
Document Date (format mm/dd/yyyy): <input type="text" name="date" size ="10"/><br /> | |
<!-- Add Senders --!> | |
<br />Sender(s): | |
<select name="senders[]" multiple="yes" size="5"> | |
<option value="empty"> --- </option> | |
<?php | |
$senderQ = "SELECT kp_pers_id, name_full FROM person ORDER BY name_last"; | |
$senderR = mysql_query($senderQ) or die(mysql_error()); | |
while($row = mysql_fetch_assoc($senderR)) { | |
echo "<option value='{$row['kp_pers_id']}'>{$row['name_full']}</option>"; | |
} | |
?> | |
</select><br /> | |
<!-- Add sender location --!> | |
Sender location: <select name="written" size="5"> | |
<?php | |
$writtenQ = "SELECT kp_place_id, place_name FROM place"; | |
$writtenR = mysql_query($writtenQ) or die(mysql_error()); | |
while($row = mysql_fetch_assoc($writtenR)) { | |
echo "<option value='{$row['kp_place_id']}'>{$row['place_name']}</option>"; | |
} | |
?> | |
</select> <br /> | |
<!-- Add Receiver(s) --!> | |
<br />Recipient(s): | |
<select name="recipients[]" multiple="yes" size="5"> | |
<option value="empty"> --- </option> | |
<?php | |
$RecQ = "SELECT kp_pers_id, name_full FROM person ORDER BY name_last"; | |
$RecR = mysql_query($RecQ) or die(mysql_error()); | |
while($row = mysql_fetch_assoc($RecR)) { | |
echo "<option value='{$row['kp_pers_id']}'>{$row['name_full']}</option>"; | |
} | |
?> | |
</select><br /> | |
<!-- Add receiver location --!> | |
Receiver location: <select name="addressed" size="5"> | |
<?php | |
$addressQ = "SELECT kp_place_id, place_name FROM place"; | |
$addressR = mysql_query($addressQ) or die(mysql_error()); | |
while($row = mysql_fetch_assoc($addressR)) { | |
echo "<option value='{$row['kp_place_id']}'>{$row['place_name']}</option>"; | |
} | |
?> | |
</select> <br /> | |
<!--Additional document information --!> | |
<br /> | |
Collection information: <input type="text" name="collection" /><br /> | |
Repository: <input type="text" name="repos" /><br /> | |
Repository Location: <input type="text" name="repos_loc" /><br /> | |
<br /> | |
Summary: <input type="text" name="summary" /><br /> | |
Key Concepts: <input type="text" name="concept" /><br /> | |
Notes: <input type="text" name="notes" /><br /> | |
<input type='submit' value='SUBMIT'/><br /> | |
</form> | |
<p>*required</p> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title>Maury Database: Document Added</title> | |
</head> | |
<body> | |
<h2>New document added to Maury database</h2> | |
<?php | |
//connect to database | |
$con = mysql_connect('server', 'user', 'password'); | |
//check connection | |
if (!$con) { | |
die('Could not connect');} | |
//else{echo 'Successful connection to mysql<br />';} | |
mysql_select_db('maury2a'); | |
//store simple values | |
$collD=mysql_real_escape_string($_POST['collection']); | |
$reposD=mysql_real_escape_string($_POST['repos']); | |
$rLocD=mysql_real_escape_string($_POST['repos_loc']); | |
$summD=mysql_real_escape_string($_POST['summary']); | |
$conD=mysql_real_escape_string($_POST['concept']); | |
$noteD=mysql_real_escape_string($_POST['notes']); | |
$splitDate = explode ('/', $_POST['date']); | |
$dateD = $splitDate[2].'-'.$splitDate[0].'-'.$splitDate[1]; | |
//create new document | |
$new_doc = "INSERT INTO document (kp_doc_id, doc_dateD, doc_collection, doc_repos, doc_repos_loc, doc_summary, doc_concepts, doc_notes) VALUES ('NULL', '".$dateD."', '".$collD."', '".$reposD."', '".$rLocD."', '".$summD."', '".$conD."', '".$noteD."')"; | |
//submit query | |
mysql_query($new_doc) or die('Error '. mysql_error()); | |
//get new prime key | |
$newDocid = mysql_insert_id(); | |
//create join link between sender and document | |
$senders=($_POST['senders']); | |
//print_r ($senders); | |
foreach($senders as $sender) { | |
if ($sender >='1') { | |
$addSender = "INSERT INTO sender (sender_doc_id, sender_pers_id) VALUES ('".$newDocid."', '".$sender."')"; | |
mysql_query($addSender) or die('Error '. mysql_error()); | |
echo "<br />Sender(s) successfully linked to document." ; | |
} | |
else{ | |
echo "<br />No senders entered, none added.";} | |
} | |
//create join between sender location and document | |
$written=mysql_real_escape_string($_POST['written']); | |
//echo "<br />Written is $written"; | |
if ($written >=1) { | |
$addWritten = "INSERT INTO written (writ_doc_id, writ_place_id) VALUES ('".$newDocid."', '".$written."')"; | |
mysql_query($addWritten) or die(mysql_error()); | |
echo "<br />Sender location successfully linked to document."; | |
} | |
else { | |
echo "<br />No location entered for sender(s)."; | |
} | |
//create join link between receiver and document | |
$recipients=($_POST['recipients']); | |
//print_r ($recipients); | |
foreach($recipients as $recipient) { | |
if ($recipient >=1) { | |
$addRec = "INSERT INTO receiver (rec_doc_id, rec_pers_id) VALUES ('".$newDocid."', '".$recipient."')"; | |
mysql_query($addRec) or die('Error updating receivers table with recipient(s).'); | |
echo "<br />Recipient(s) successfully linked to document."; | |
} | |
else{ | |
echo "<br />No recipient(s) entered, none added.";} | |
} | |
//create join between sender location and document | |
$address=mysql_real_escape_string($_POST['addressed']); | |
if ($address >=1) { | |
$addAddress = "INSERT INTO received (recd_doc_id, recd_place_id) VALUES ('".$newDocid."', '".$address."')"; | |
mysql_query($addAddress) or die('Error updating received table' . mysql_error()); | |
echo "<br />Recipient location successfully linked to document."; | |
} | |
else { | |
echo "<br />No location entered for recipient(s).";} | |
echo "<br /> Success: new document added, id number $newDocid"; | |
echo "<br /> <a href='form_doc.php'>Back</a>"; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment