Home > Mobile >  Content Editable Field not working in PHP but works in HTML
Content Editable Field not working in PHP but works in HTML

Time:02-25

OK I know the code for editable field working in HTML, inline edit. But I am unable to use the same i PHP code

I am attaching below HTML working one and PHP in echo where I am lacking

Please Guide

Thanks

HTML (WORKING)

<td style="text-align:center;" contenteditable="true" data-old_value="<?php echo $row1["view"];?>"  onBlur="saveInlineEdit(this,'view','<?php echo $row1["id"]; ?>')" onClick="highlightEdit(this);"><?php echo $row1["view"]; ?></td>

PHP (Surely there is a mistake by me - Not Working)

echo "<td style='text-align:center;' contenteditable='true' data-old_value='<?php echo $row1["view"];?>'  onBlur='saveInlineEdit(this,"view","<?php echo $row1["id"]; ?>")' onClick='highlightEdit(this);'><?php echo $row1["view"]; ?></td>
    

CodePudding user response:

<?php echo is only used when you're in HTML output mode and need to get back into PHP execution. But you're already executing PHP. It doesn't do anything special inside a string, it's just echoed literally.

Just use normal variable substitution or concatenation.

echo "<td style='text-align:center;' contenteditable='true' data-old_value='{$row1["view"]}'  onBlur='saveInlineEdit(this,\"view\",\"{$row1["id"];\")' onClick='highlightEdit(this);'>{$row1["view"]}</td>

Also, you need to escape the literal " inside the string.

CodePudding user response:

I doubt that the excepted answer will work, atleast one " is missing. I also prefer concatenation, since it is better readable. Concatenation:

echo '<td style="text-align:center;" contenteditable="true" data-old_value="' . $row["notess"] . '" onBlur="saveInlineEdit(this,\"notess\",' . $row["id"] . ')" onClick="highlightEdit(this);">' . $row["notess"] . '</td>';

you could also go the dirty way with output buffering:

<?php ob_start(); ?>
<td style="text-align:center;" contenteditable="true" data-old_value="<?php echo $row1["view"];?>"  onBlur="saveInlineEdit(this,'view','<?php echo $row1["id"]; ?>')" onClick="highlightEdit(this);"><?php echo $row1["view"]; ?></td>
<?php ob_end_clean(); ?>
  • Related