I am troubling to save my records in UPDATE SET statement within PHP. Im using JavaScript to update the record on submit. See below code:
/* Update Record */
$(document).on('submit', '#emp-UpdateForm', function() {
$.post("update.php", $(this).serialize())
.done(function(data){
$("#dis").fadeOut();
$("#dis").fadeIn('slow', function(){
$("#dis").html('<div class="alert alert-info">'+data+'</div>');
$("#emp-UpdateForm")[0].reset();
$("body").fadeOut('slow', function()
{
$("body").fadeOut('slow');
window.location.href="home.php";
});
});
});
return false;
});
/* Update Record */
Note that the above method is retrieving the file update.php where the UPDATE SET statement lies. See code:
if(isset($_POST)){
$stmt = $update->runQuery("UPDATE IndividualProduct SET name=:name,model=:model,manufacturer=:manufacturer,productionYear=:productionYear,color=:color,purchaseAmount=:purchaseAmount WHERE id_product=:id");
$stmt->bindparam(":name",$pname);
$stmt->bindparam(":model",$pmodel);
$stmt->bindparam(":manufacturer",$pmanuf);
$stmt->bindparam(":productionYear",$pyear);
$stmt->bindparam(":color",$pcolor);
$stmt->bindparam(":purchaseAmount",$pamount);
$stmt->bindparam(":id",$id);
$id = $_POST['id_product'];
$pmanuf = $_POST['pmanuf'];
$pname = $_POST['pname'];
$pmodel = $_POST['pmodel'];
$pyear = $_POST['pyear'];
$pcolor = $_POST['pcolor'];
$pamount = $_POST['pamount'];
$stmt->execute();}
Here is the edit_form.php where the records from column are retrieved when editing:
<form method='post' id='emp-UpdateForm' action='#'>
<table class='table table-bordered'>
<input type='hidden' name='id' value='<?php echo $row['id_product']; ?>' />
<tr>
<td>Mærke</td>
<td><input type='text' name='manufacturer' class='form-control' value='<?php echo $row['manufacturer']; ?>' required></td>
</tr>
<tr>
<td>Navn</td>
<td><input type='text' name='name' class='form-control' value='<?php echo $row['name']; ?>' required></td>
</tr>
<tr>
<td>Model</td>
<td><input type='text' name='model' class='form-control' value='<?php echo $row['model']; ?>' required></td>
</tr>
<tr>
<td>Årgang</td>
<td><input type='text' name='productionYear' class='form-control' value='<?php echo $row['productionYear']; ?>' required></td>
</tr>
<tr>
<td>Pris</td>
<td><input type='text' name='purchaseAmount' class='form-control' value='<?php echo $row['purchaseAmount']; ?>' required></td>
</tr>
<tr>
<td>Farve</td>
<td><input type='text' name='color' class='form-control' value='<?php echo $row['color']; ?>' required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update" id="btn-update">
<span class="glyphicon glyphicon-plus"></span> Save Updates
</button>
</td>
</tr>
</table>
When I enter another value like "Acer" in a row, as for example in the "manufacturer" row where the value = "Asus" and click on submit (Save updates), the value changes back to "Asus" and is not being updated to the my input.