Hello. I am trying to update data using a form via a field [id] from a previous page. I am trying to show the data already in the database so that I can then update it.
The issue is with a undefined variable - I have two, $r and $record, In a test $record was the problem (still is) so I changed to match $r = mysqli_query($dbc, $q), but i still get the error.
I include the whole code page in case I’m missing something some where in the PHP.
<?php include 'db-connection/dbcon.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Ancient Egypt">
<title>My Family Tree</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<!-- jQuery CSS -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<!-- site styles -->
<link rel="stylesheet" type="text/css" media="screen" href="css/styles.css">
<!-- jQuery CDN -->
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- jquery UI -->
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Update Record</h1>
<h2><a href='index.php' class='btn btn-default'>Create New Record</a> | <a href='view.php' class='btn btn-default'>Record List</a></h2>
<h5 class="alert text-center"><strong>No details (N/D), Not Applicable (N/A)</strong></h5>
<?php
if(isset($_POST['submitted']) == 1){
if(isset($_POST['id'])) {
$q = "UPDATE records SET uid = $_POST[uid], first = $_POST[first], middle = $_POST[middle], last = $_POST[last], dob = $_POST[dob], birthloc = $_POST[birthloc], bc = $_POST[bc], bcregdate = $_POST[bcregdate], bcregloc = $_POST[bcregloc], bcocert = $_POST[bcocert], bco = $_POST[bco], bcoloc = $_POST[bcoloc], bcodate = $_POST[bcodate], father = $_POST[father], mother = $_POST[mother], siblings = $_POST[siblings], children = $_POST[children], marriagecert = $_POST[marriagecert], marriedto = $_POST[marriedto], marriedat = $_POST[marriedat], marriedon = $_POST[marriedon], divorced = $_POST[divorced], divorcedon = $_POST[divorcedon], partner = $_POST[partner], partnername = $_POST[partnername], deathcert = $_POST[deathcert], diedon = $_POST[diedon], cause = $_POST[cause], deathregdate = $_POST[deathregdate], ic = $_POST[ic], icdate = $_POST[icdate], employ = $_POST[employ], address = $_POST[address], other = $_POST[other] WHERE id = $_GET[id]";
} else {
$q = "INSERT INTO records (uid, first, middle, last, dob, birthloc, bc, bcregdate, bcregloc, bcocert, bco, bcoloc, bcodate, father, mother, siblings, children, marriagecert, marriedto, marriedat, marriedon, divorced, divorcedon, partner, partnername, deathcert, diedon, cause, deathregdate, ic, icdate, employ, address, other) VALUES ('$_POST[uid]', '$_POST[first]', '$_POST[middle]', '$_POST[last]', '$_POST[dob]', '$_POST[birthloc]', '$_POST[bc]', '$_POST[bcregdate]', '$_POST[bcregloc]', '$_POST[bcocert]', '$_POST[bco]', '$_POST[bcoloc]', '$_POST[bcodate]', '$_POST[father]', '$_POST[mother]', '$_POST[siblings]', '$_POST[children]', '$_POST[marriagecert]', '$_POST[marriedto]', '$_POST[marriedat]', '$_POST[marriedon]', '$_POST[divorced]', '$_POST[divorcedon]', '$_POST[partner]', '$_POST[partnername]', '$_POST[deathcert]', '$_POST[diedon]', '$_POST[cause]', '$_POST[deathregdate]', '$_POST[ic]', '$_POST[icdate]', '$_POST[employ]', '$_POST[address]', '$_POST[other]')";
}
$r = mysqli_query($dbc, $q);
if($r){
echo "<div class='alert alert-success'>Record was updated.</div>";
}
else{
echo "<div class='alert alert-danger'>Unable to update record. Error: </div>".mysqli_error($dbc);
echo "<div class='alert alert-danger'>.$q.</div>";
}
} // end if:
?>
<form action="update.php" method="post" role="form">
<div class="container">
<div class="row">
<div class="col-md-12 block text-center">
<h4>UID</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-12 block2 text-center">
<h4>
<input name="uid" id="uid" type="text" value="<?php echo $r['uid']; ?>">
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block text-center">
<h4>First name</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Middle name(s)</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Last name</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="first" id="first"><?php echo $record['first']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="middle" id="middle"><?php echo $record['middle']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="last" id="last"><?php echo $record['last']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block text-center">
<h4>Date of birth</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Location of birth</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Birth certificate</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="dob" id="dob"><?php echo $record['dob']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="birthloc" id="birthloc"><?php echo $record['birthloc']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bc" id="bc"><?php echo $record['bc']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block text-center">
<h4>BC Registration date</h4>
</div>
<div class="col-md-4 block text-center">
<h4>BC Registration location</h4>
</div>
<div class="col-md-4 block text-center">
<h4>BCO certificate</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bcregdate" id="bcregdate"><?php echo $record['bcregdate']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bcregloc" id="bcreloc"><?php echo $record['bcregdate']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bcocert" id="bcocert"><?php echo $record['bcocert']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block text-center">
<h4>BCO</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Location BCO</h4>
</div>
<div class="col-md-4 block text-center">
<h4>BCO date</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bco" id="bco"><?php echo $record['bcocert']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bcoloc" id="bcoloc"><?php echo $record['bcoloc']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="bcodate" id="bcodate"><?php echo $record['bcodate']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block text-center">
<h4>Father</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Mother</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Sibling(s)</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Children</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="father" id="father"><?php echo $record['father']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="mother" id="mother"><?php echo $record['mother']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="siblings" id="siblings"><?php echo $record['siblings']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="children" id="children"><?php echo $record['children']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block text-center">
<h4>Marriage certificate</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Married to</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Married at</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Married on</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="marriagecert" id="marriagecert"><?php echo $record['marriagecert']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="marriedto" id="marriedto"><?php echo $record['marriedto']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="marriedat" id="marriedat"><?php echo $record['marriedat']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="marriedon" id="marriedon"><?php echo $record['marriedon']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block text-center">
<h4>Divorced</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Divorced on</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Partner</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Partner name</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="divorced" id="divorced"><?php echo $record['divorced']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="divorcedon" id="divorcedon"><?php echo $record['divorcedon']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="partner" id="partner"><?php echo $record['partner']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="partnername" id="partnername"><?php echo $record['partnername']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block text-center">
<h4>Death certificate</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Died on</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Cause</h4>
</div>
<div class="col-md-3 block text-center">
<h4>Death registered on</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="deathcert" id="deathcert"><?php echo $record['deathcert']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="diedon" id="diedon"><?php echo $record['diedon']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="cause" id="cause"><?php echo $record['cause']; ?></textarea>
</h4>
</div>
<div class="col-md-3 block2 text-center">
<h4>
<textarea name="deathregdate" id="deathregdate"><?php echo $record['deathregdate']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block text-center">
<h4>Interred / Cremated</h4>
</div>
<div class="col-md-4 block text-center">
<h4>IC on</h4>
</div>
<div class="col-md-4 block text-center">
<h4>IC location</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="ic" id="ic"><?php echo $record['ic']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="icdate" id="icdate"><?php echo $record['icdate']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="icloc" id="icloc"><?php echo $record['icloc']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block text-center">
<h4>Employment details</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Address from - to</h4>
</div>
<div class="col-md-4 block text-center">
<h4>Other</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="employ" id="employ"><?php echo $record['employ']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="address" id="address"><?php echo $record['address']; ?></textarea>
</h4>
</div>
<div class="col-md-4 block2 text-center">
<h4>
<textarea name="other" id="other"><?php echo $record['other']; ?></textarea>
</h4>
</div>
</div><!-- row end: -->
<div class="row">
<div class="col-md-12 block text-center">
<input type='submit' value='Update Record' class='btn btn-primary' />
</div>
<input type="hidden" id="submitted" name="submitted">
</div><!-- row end: -->
</div><!-- container end: -->
</form><!-- form end: -->
</body>
</html>