CodeIgniter Forums
Edit value on db with ' or " - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Edit value on db with ' or " (/showthread.php?tid=74153)



Edit value on db with ' or " - pippuccio76 - 08-04-2019

hi , sorry for english , if i want t a value inserted by textarea i have problem with '  .

This is the code :


Code:
 <input class='form-control' type='text' value='<?=$val?>' id='id_class_descrizione_problema' name='descrizione_problema' maxlength='65535' >

$val is a value from db .
How can i prevent error textwith ' or " or \ ?


RE: Edit value on db with ' or &quot; - InsiteFX - 08-04-2019

PHP.NET - htmlspecialchars

PHP.NET - htmlentities


RE: Edit value on db with ' or &quot; - Wouter60 - 08-04-2019

This is not the right html code for a textarea. What you should do is this:
PHP Code:
<textarea name="descrizione_problema" id="id_class_descrizione_problema" class="form-control" rows="12" maxlength="65535">
<?= 
$val;?>
</textarea> 



RE: Edit value on db with ' or " - includebeer - 08-05-2019

Use the esc() helper function:

PHP Code:
<input type="text" name="myfield" value="<?= esc($string); ?>" /> 



RE: Edit value on db with ' or " - InsiteFX - 08-05-2019

@includebeer, that's a CI 4 method. You can use html_escape(value), or form_prep().


RE: Edit value on db with ' or " - includebeer - 08-05-2019

(08-05-2019, 07:56 AM)InsiteFX Wrote: @includebeer, that's a CI 4 method. You can use html_escape(value), or form_prep().

Yeah, but people should really develop new projects with CI4!  Big Grin