Skip to content
Advertisement

var in textarea from sql?

I tried to make a form with textarea content taken from sql and it’s working well except for 1 thing i want to make…

i have some text in the sql like “hi $name, welcome” (for example) and when i echo it in the textarea i get the same “hi $name, welcome” but i want the $name to change for what i want…

<?php
    $supplier = "David";
    $branch = "name";
    $msg = $row['msg'];
?>
      <textarea rows="7" name="msg" cols="50" style="font-size: 11"><?php echo $msg; ?></textarea>

EDIT: that’s what i get: enter image description here

and that’s the sql: enter image description here

how i can change it?

thanks!

Advertisement

Answer

If you want to store a message in the database and replace some words on output, don’t save it as PHP code. Create a template with placeholders for the variable data instead, something like:

Hi, {supplier}. Lorem ipsum {branch} 

and then just replace those using str_replace()

$msg = str_replace(['{supplier}', '{branch}'], [$supplier, $branch], $msg);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement