glennanyway
glennanyway

Reputation: 2133

MySQL query using special characters

Every time I insert data using an SQL query I get an error. I suspect it's because of the apostrophes in the $post value.

The SQL query is:

$sql="INSERT INTO posts (id_str, post, time, rt) VALUES ('$id_str','$post', '$time', '$rt')";

but my $post value is

$post = "My test posts are not as 'inconsistent' as before";

What should I do?

Upvotes: 0

Views: 708

Answers (2)

user557846
user557846

Reputation:

The most basic solution is to mysql_real_escape_string().

Upvotes: 1

Corubba
Corubba

Reputation: 2243

mysql_real_escape_string() should do the escape for you.

Upvotes: 3

Related Questions