Created
September 26, 2012 20:47
-
-
Save mebrett/3790489 to your computer and use it in GitHub Desktop.
Trying to update records
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
<html> | |
<?php | |
include "connect-db.php"; | |
//create form function | |
function renderForm($id='', $dateF='', $dateD='', $collection='', $repos='', $repos_loc='') | |
{ ?> | |
<form action="" method="post"> | |
<?php if ($id != '') { ?> | |
<input type="hidden" name="docID" value="<?php echo $id; ?>" /> | |
<p>Doc ID: <?php echo $id; ?></p> | |
<?php } ?> | |
<br /> | |
<?php | |
echo "ID is $id, Collection is $collection (line15)<br />"; | |
?> | |
<!-- Add document date --!> | |
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 /> | |
<!-- Additional document information --!> | |
<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" 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 /> | |
<input type='submit' value='SUBMIT'/><br /> --!> | |
</form> | |
<?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)"; | |
// | |
if($stmt = $mysqli->prepare("SELECT kp_doc_id, doc_collection, doc_repos, doc_repos_loc, FROM document WHERE kp_doc_id=?")) { | |
$stmt->bind_param("i", $id); | |
$stmt->execute(); | |
$stmt->bind_result($id, $collection, $repos, $repos_loc); | |
$stmt->fetch(); | |
$stmt->close();} | |
echo "<br />$id, $collection (line54)<br />"; | |
renderForm($id, $dateF, $dateD, $collection, $repos, $repos_loc); | |
} | |
else {echo "Captain, we have a problem";} | |
} | |
$mysqli->close(); | |
?> | |
</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
<?php | |
$mysqli = new mysqli('localhost', 'root', 'root', 'maury2'); | |
$lastQ = "SELECT kp_pers_id, SUBSTRING_INDEX(name_full, ',', 1) FROM person"; | |
$resultL = $mysqli->query($lastQ); | |
while($row = $resultL->fetch_row()) { | |
//printf("%s: <strong>%s</strong><br>", $row[0], $row[1]); | |
// add an element to $names array (and create it if there isn't one) | |
// $row[1] refers to the names that are pulled from the database above | |
$names[] = $row[1]; | |
$personIDs = $row[0]; | |
} | |
foreach($names as $name){ | |
echo "Person ID: $personIDs, Name: $name <br />"; | |
$addL = "UPDATE person SET name_last='".$name."' WHERE kp_pers_id='".$personID."'"; | |
$result1 = $mysqli->query($addL); | |
if($result1){ | |
echo "<br />";} | |
else{echo "error";} | |
} | |
?> |
Edits as recommended above worked!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 12: $names[$row[0]] = $row[1]; // this also adds an element to array, but at position labeled $row[0](= personID)
line 16: foreach ($names as $personID => $name) {