Jump to content

MySQL errors with apostrophe


PWD

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....
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.