Jump to content


This topic is now archived and is closed to further replies.


MySQL errors with apostrophe

Recommended Posts

I think I missed something in MySQL 101 years ago, or maybe a new thing with MySQL 5.0.15, but my simple insert statement from a textfield error out [b]ONLY[/b] when an apostrophe is used within the text field:

[code]<!-- Textfield Text example -->
We went down to Michael's house
<!-- End Textfield entry -->[/code]

[code]MySQL Statement:
$query = "INSERT into TABLE(text_field) VALUES('$_POST[textfield]')";[/code]

What do I need to include in my INSERT statement to allow apostrophes? addslashes()?

My gratitude ahead of time....

Share this post

Link to post
Share on other sites
Yes you should uses addslashes also [b]NEVER[/b] place POST'd data straight into a mysql query with out validating the data/eascaping the data with addslashes, htmelentities or use mysql_real_escape_string. So this is what your code should be like:
[code]$textfield = addslashes($_POST['textfield']);
$query = "INSERT into TABLE(text_field) VALUES('$textfield')";[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.