I am building an webpage that has editable data fields linked with MySql database.
<th>CONTACT 1 NUMBER*</th>
<td bgcolor="#FFFFFF" contenteditable="true" data-old_value="<?php echo $rows["emr1_number"]; ?>" onBlur="saveInlineEdit(this,'emr1_number','<?php echo $rows["safr_id"]; ?>','<?php echo $userRow['userId']; ?>')"><?php echo $rows["emr1_number"]; ?></td>
The above code is used in html side to show data and get new data if the fields are edited.
function saveInlineEdit1(editableObj,column,id,uid) {
// no change change made then return false
if($(editableObj).attr('data-old_value') === editableObj.innerHTML)
return false;
// send ajax to update value
$(editableObj).css("background","#FFF url(loader.gif) no-repeat right");
$.ajax({
url: "saveInlineEdit1.php",
cache: false,
data:'column='+column+'&value='+editableObj.innerHTML+'&id='+id+'&uid='+uid,
success: function(response) {
console.log(response);
// set updated value as old value
$(editableObj).attr('data-old_value',editableObj.innerHTML);
$(editableObj).css("background","#FDFDFD");
}
});
}
Above JS is used to get edited data and make an AJAX call.
this is saveInlineEdit1.php
<?php
include_once("db_connect.php");
$sql = "UPDATE coin_location set ".$_REQUEST["column"]."='".$_REQUEST["value"]."' WHERE coin_id='".$_REQUEST["id"]."' AND userId='".$_REQUEST["uid"]."'";
mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
echo "saved";
?>
Everything is working fine. Only problem I have is, If am editing the data field with "+" sign, For ex, changing the data "hello" with "+hello" in webpage. Actually the data altered in database must be "+hello" but i get " hello". An empty space is replaced in the place of "+" sign.
Please, help me to get rid of this.
Thanks.