Display documents and edit/add new for Maury DB
<?php | |
//server info | |
$server = 'server'; | |
$user = 'user'; | |
$pass = 'pass'; | |
$db = 'data'; | |
// connect to the database | |
$mysqli = new mysqli($server, $user, $pass, $db); | |
// check connection | |
if (!$mysqli) { | |
exit('Connect failed: '. mysqli_connect_error()); | |
} | |
//create form function | |
function renderForm($id='', $dateF='', $dateD='', $collection='', $repos='', $repos_loc='', $summary='', $concept='', $notes='', $images='', $senderID='', $writID='') | |
{ ?> | |
<html> | |
<head> | |
</head> | |
<body> | |
<form action='' method='post'> | |
<?php if ($id != '') { ?> | |
<input type='hidden' name='docID' value='<?php echo $id; ?>' /> | |
<h2>Beginning of Form</h2> | |
<p>Doc ID: <?php echo $id; ?></p> | |
<?php } ?> | |
<br /> | |
<?php | |
//echo "ID is $id, Collection is $collection (line15) Sender ID is $senderID, WritID is $writID<br />"; | |
//print_r($senderID); echo "<br />"; | |
echo "Value of mysqli: "; | |
var_dump($mysqli); | |
echo "<br />"; | |
?> | |
Document Date (format mm/dd/yyyy): <input type='text' name='dateD' value='<?php echo $dateD; ?>' size ='10' /><br /> | |
Document Date (if only year or month, otherwise copy from above): <input type='text' name='dateF' value='<?php echo $dateF; ?>' size ='10' /></br /> | |
<?php | |
$senderQ = "SELECT kp_pers_id, name_full FROM person ORDER BY name_last"; | |
var_dump($senderQ); | |
$senderResult = mysqli_query($mysqli, $senderQ) or die; | |
echo "<br /> Var Dump Sender Result: "; | |
var_dump($senderResult); | |
?> | |
<br />Sender(s): | |
<select name="senders[]" multiple="yes" size="5"> | |
<option value="empty"> --- </option> | |
<?php | |
while($row = mysqli_fetch_assoc($senderResult)) { | |
echo "<option value='{$row['kp_pers_id']}'>{$row['name_full']}</option>"; | |
} | |
?> | |
</select><br /> | |
<!-- Add sender location --> | |
<?php | |
$writtenQ = "SELECT kp_place_id, place_name FROM place"; | |
var_dump($writtenQ); | |
$writtenR = $mysqli->query($writtenQ) or die(mysql_error()); | |
?> | |
Sender location: <select name="written" size="5"> | |
<?php while($row = mysqli_fetch_assoc($writtenR)) { | |
echo "<option value='{$row['kp_place_id']}'>{$row['place_name']}</option>"; | |
} | |
?> | |
</select> <br /> | |
<br /> | |
Collection information: <input type='text' name='collection' value='<?php echo $collection; ?>' /><br /> | |
Repository: <input type='text' name='repos' value='<?php echo $repos; ?>'/><br /> | |
Repository Location: <input type="text" name="repos_loc" value='<?php echo $repos_loc; ?>' /><br /> | |
<br /> | |
Summary: <input type='text' name='summary' size='100' value="<?php echo $summary; ?>" /><br /> | |
Key Concepts: <input type='text' name='concept' value='<?php echo $concept; ?>' /><br /> | |
Notes: <input type='text' name='notes' value='<?php echo $notes; ?>'/><br /> | |
Images: <input type='text' name='imgs' value='<?php echo $images; ?>' /><br /> | |
<input type='submit' name='submit' value='SUBMIT'/><br /> | |
</form> | |
<br /> | |
</body> | |
</html> | |
<?php | |
} | |
// EDIT RECORD | |
// if the 'id' variable is set in the URL, we know that we need to edit a record | |
if (isset($_GET['kp_doc_id'])) { | |
//echo "Isset Success. <br />"; | |
// make sure the 'id' value is valid | |
if (is_numeric($_GET['kp_doc_id']) && $_GET['kp_doc_id'] > 0) { | |
// get 'id' from URL | |
$id = $_GET['kp_doc_id']; | |
echo "ID is $id (line46)"; | |
echo "<br /><br />Value of mysqli: "; | |
var_dump($mysqli); | |
echo "<br />"; | |
// | |
if($stmt = $mysqli->prepare("SELECT kp_doc_id, doc_dateF, doc_dateD, doc_collection, doc_repos, doc_repos_loc, doc_summary, doc_concepts, doc_notes, doc_images FROM document WHERE kp_doc_id=?")) { | |
$stmt->bind_param("i", $id); | |
$stmt->execute(); | |
$stmt->bind_result($id, $dateF, $dateD, $collection, $repos, $repos_loc, $summary, $concept, $notes, $images); | |
$stmt->fetch(); | |
$stmt->close(); | |
} | |
//echo "<br />$id, $collection, $notes (line54)<br />"; | |
// query and fetch sender | |
$getSender = "SELECT person.kp_pers_id, person.name_full, sender.sender_doc_id, sender.sender_pers_id FROM person, sender WHERE person.kp_pers_id = sender.sender_pers_id AND sender.sender_doc_id=".$id ; | |
$senderArray = mysqli_query($mysqli, $getSender); | |
// print_r($senderArray); | |
while ($row = mysqli_fetch_assoc($senderArray)) { | |
$senderID[] = $row['kp_pers_id'];} | |
//query and fetch sender location | |
/* $getWritten = "SELECT place.kp_place_id, place.place_name FROM written, place WHERE place.kp_place_id=written.writ_place_id AND written.writ_doc_id=".$id ; | |
echo "<br /> getWritten: <em> ".$getWritten."</em><br />";*/ | |
//run form | |
renderForm($id, $dateF, $dateD, $collection, $repos, $repos_loc, $summary, $concept, $notes, $images, $senderID, $writID); | |
} | |
else {echo "Captain, we have a problem";} | |
} | |
else{renderForm();} | |
?> |
<html> | |
<head> | |
</head> | |
<h1>Documents in the Maury Database</h1> | |
<?php | |
$mysqli = new mysqli("localhost", "root", "root", "maury2"); | |
/* check connection */ | |
if (mysqli_connect_errno()) { | |
printf("Connect failed: %s\n", mysqli_connect_error()); | |
exit(); | |
} | |
$queryDoc = "Select kp_doc_id, doc_dateF, doc_dateD, doc_collection, doc_repos, doc_repos_loc, doc_concepts, doc_summary, doc_notes, doc_images from document"; | |
echo "<br />Query: $queryDoc <br />"; | |
echo"<table border='1' cellpadding='5'>"; | |
echo "<tr><th>Doc ID</th><th>Date</th><th>Sender</th><th>Recipient</th><th>Summary</th><th>Collection Info</th><th>Concepts</th><th>View</th><th>Edit</th></tr>"; | |
if ($resultDoc = $mysqli->query($queryDoc)){ | |
while ($row = $resultDoc->fetch_array()) { | |
while ($row = $resultDoc->fetch_object()){ | |
echo "<tr>"; | |
echo "<td>" .$row->kp_doc_id. "</td>"; | |
echo "<td>" .$row->doc_dateD. " (F: ".$row->doc_dateF. ")</td>"; | |
echo "<td></td><td></td>"; | |
echo "<td>" .$row->doc_summary. "</td>"; | |
echo "<td>" .$row->doc_collection.", " .$row->doc_repos. "</td>"; | |
echo "<td>" .$row->doc_concepts. "</td>"; | |
echo "<td> <a href=''>View</a></td>"; | |
echo "<td><a href='editdoc.php?kp_doc_id=" . $row->kp_doc_id . "'>Edit</a></td>"; | |
} | |
} | |
} | |
echo "</table>"; | |
mysqli_close($mysqli); | |
?> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment