Hello. I have a problem with UPDATE. The data is retrieved from the database without error, but the issue arises when I change some data and then try to update it. If the update is successful the page is redirected back to index. Since this does not happen, I assume there is an issue in the code.
The php code:
<?php
require_once("dbcon/dbc.php");
if(!empty($_POST["save_record"])) {
$pdo_statement = $dbh->prepare("update pages set
pagelinks='" . $_POST[ 'pagelinks' ] . "',
title='" . $_POST[ 'title' ] . "'.
body='" . $_POST[ 'body' ]. "',
side='". $_POST[ 'side' ]. "'.
sourceref='" . $_POST[ 'sourceref' ]. "',
sourceimg='" . $_POST[ 'sourceimg' ]. "'
where id=" . $_GET["id"]);
$result = $pdo_statement->execute();
if($result) {
header('location:index.php');
}
}
$pdo_statement = $dbh->prepare("SELECT * FROM pages where id=" . $_GET['id']);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
?>
This is the form (including table) html:
<table class="table table-bordered xTable zTable">
<form name="frmAdd" action="" method="POST">
<tr>
<td>
<h3>Page Links</h3>
</td>
<td>
<input type="text" name="pagelinks"value="<?php echo $result[0]['pagelinks']; ?>">
</td>
</tr>
<tr>
<td>
<h3>Title</h3>
</td>
<td>
<input type="text" name="title" value="<?php echo $result[0]['title']; ?>">
</td>
</tr>
<tr>
<td>
<h3>Body</h3>
</td>
<td>
<textarea name="body"><?php echo $result[0]['body']; ?></textarea>
</td>
</tr>
<tr>
<td>
<h3>Side</h3>
</td>
<td>
<textarea name="side"><?php echo $result[0]['side']; ?></textarea>
</td>
</tr>
<tr>
<td>
<h3>Source Ref</h3>
</td>
<td>
<textarea name="sourceref"><?php echo $result[0]['sourceref']; ?></textarea>
</td>
</tr>
<tr>
<td>
<h3>Source Img</h3>
</td>
<td>
<textarea name="sourceimg"><?php echo $result[0]['sourceimg']; ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" class="text-center">
<input name="add_record" class="btn btn-warning" type="submit" value="Update">
</td>
</tr>
</form>
</table>
I understand you can find out if there are errors with php code, but I have no idea how to do this, or how to implement it within my code.
I would be grateful if you can point out the errors, and if there is code to identify the errors I would appreciate the code as it would appear in mine.
Thanks in advance.