I am using angularjs php form post to insert or update row. Currently I have working example below and I want to know if this can be written in shorter way so that it can used in both UPDATE and INSERT scenario. I want to submit the whole FORM not just the defined value. Thanks for help.
function update($con){
$postdata = file_get_contents("php://input", true);
$request = json_decode($postdata);
$idx = $request->idx;
$images = $request->images;
$collection = $request->collection;
$title = $request->title;
$description = $request->description;
$height = $request->height;
$width = $request->width;
$length = $request->length;
$weight = $request->weight;
$price = $request->price;
$availability = $request->availability;
$active = $request->active;
$method = $request->method;
$searchkeys = $request->searchkeys;
$materialused = $request->materialused;
if(is_array($images)){
$implodeImg = implode(',', $images);
}else{
$implodeImg = $images;
}
$sqlIn = "UPDATE prodList_1 SET
idx = '$idx',
images = '$implodeImg',
collection = '$collection',
title = '$title',
description = '$description',
height = '$height',
width = '$width',
length = '$length',
weight = '$weight',
price = '$price',
availability = '$availability',
active = '$active',
method = '$method',
searchkeys = '$searchkeys',
materialused = '$materialused'
WHERE idx = '$idx'";
if (mysqli_query($con, $sqlIn)) {
echo "Record Updated successfully";
} else {
echo "Error: " . $sqlIn . "<br>" . mysqli_error($con);
}
}