I have a database field that is long test that's a whole users page. I want to allow the user to edit parts of their page. It is not possible to search the long string of text and just update certain parts so I want to have ID's in the code and do a dom getElementbyId and change the inner html in the correct spots and then insert the new code into db. However this works when I'm echoing to the page but not inserting back in to database. If this is confusing see what I mean below
This works, when I echo the $var it says hello guy:
<?php
$newVar = "hello guy";
$var = "<p id='hello world'></p>";
echo $var;
?>
<script>
document.getElementById("demo").innerHTML = "<?php echo $newVar; ?>";
</script>
But when inserted into database it is hello world, not hello guy:
<?php
$newVar = "hello guy";
$var = "<p id='hello world'></p>";
$stmt = $conn->prepare("INSERT INTO temp429 (post_content) VALUES (?)");
$stmt->bind_param("s", $var);
$stmt->execute();
?>
<script>
document.getElementById("demo").innerHTML = "<?php echo $newVar; ?>";
</script>
I'm expecting hello guy to be inserted into the database like it shows when echoed but does not do this. Is there any solution around this?
$var
in yourbind_param
call, but expecting it to be the value from$newVar
?$var
more like a template? Like, would it be accurate to say$var = 'Good afternoon <first name here>, your current balance is <balance>';
, and you'd want to be able to automatically substitute data into<first name here>
and<balance>
?