note 5296 modified in ref.strings by sander
| From: | sander@php.net | Date: | Sun, 07 Apr 2002 13:36:19 +0000 |
| Subject: | note 5296 modified in ref.strings by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28913@lists.php.net to get a copy of this message | ||
For a MySQL problem (where a user might put quotes in a text field from a form) use addslashes() to
escape all quotes (single and double). For example:
// Assuming 'textstuff' is from a form
$mytextstuff = addslashes($textstuff);
$sql = "insert into MyTable set MyField='$mytextstuff'";
Also if you are working with html forms and/or text fields from databases a lot you'll probably
want to read up on commands like htmlspecialchars() as well (a field like "foo<bar>"
might not throw MySQL off but it won't display correctly in an html page).
--was--
For a MySQL problem (where a user might put quotes in a text field from a form) use addslashes() to
escape all quotes (single and double). For example:
<p>
// Assuming 'textstuff' is from a form<br>
$mytextstuff = addslashes($textstuff);<br>
$sql = "insert into MyTable set MyField='$mytextstuff'";<br>
<p>
Also if you are working with html forms and/or text fields from databases a lot you'll probably
want to read up on commands like htmlspecialchars() as well (a field like "foo<bar>"
might not throw MySQL off but it won't display correctly in an html page).
http://www.php.net/manual/en/ref.strings.php