Shell PHP file writes to MySQL, but not if it has apostrophe

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
evmaster
Forum Newbie
Posts: 2
Joined: Wed Jan 17, 2007 2:26 am

Shell PHP file writes to MySQL, but not if it has apostrophe

Post by evmaster »

Hey everyone,

I'm trying to set up a system that lets me post messages on my blog by email.

I have an email address set up so that any mail sent to it will be written into the blog's MySQL database (Subject -> message title | Body -> message body).
I have a line of code that emails a notification message to my email account just so I know the script has worked.
Everything works perfectly, as long as the message doesn't contain characters like apostrophies. If it does then nothing will be written into the MySQL, but I still get the notification email which shows the message as I sent it.

Using PHPMyAdmin to insert values works fine, no matter how long, and all the other scripts I have tried with my server haven't given me trouble - it seems to have something to do with the fact that the data from an email message.

This is the script that's giving trouble, with the login info removed of course:
http://www.evan.net.au/send_to_blog_web.txt

Thanks for your time,
Evan
evmaster
Forum Newbie
Posts: 2
Joined: Wed Jan 17, 2007 2:26 am

Post by evmaster »

I seem to have fixed this with the addslashes() command.

Thanks!
-Evan
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

you might want to look at mysql_real_escape_string()

:)
Post Reply