0

MySQL is giving a 1064 on an escaped string.

$date is set above.
$article_clean = mysqli_real_escape_string($dbc,$article);
$guid_clean= mysqli_real_escape_string($dbc,$guid_clean);
$pub_date_clean = mysqli_real_escape_string($dbc,$pub_date);
$title_clean = mysqli_real_escape_string($dbc,$title);
$query = "INSERT INTO blog_post (date,article,link,pub_date,title) VALUES ('$date',$article_clean','$guid_clean','$pub_date_clean','$title_clean')";

mysqli_query($dbc, $query);

Why?

4
  • @piotrm THANK YOU!!!! I guess after a few hours I should take a break. Commented Jan 23, 2012 at 4:56
  • Just something I noted, if you're using mysqli, why don't you use prepared statements? Commented Jan 23, 2012 at 5:15
  • @Mike I guess I don't know about those. Do you have any information on that? Commented Jan 23, 2012 at 5:54
  • Prepared statements are one of the main advantages of mysqli instead of mysql_* functions. Check the documentation here: php.net/manual/en/mysqli.prepare.php Commented Jan 23, 2012 at 23:10

3 Answers 3

1

You have missed a single quote, Rewrite your query line with this one:-

$query = "INSERT INTO blog_post (date,article,link,pub_date,title) VALUES ('$date','$article_clean','$guid_clean','$pub_date_clean','$title_clean')";
Sign up to request clarification or add additional context in comments.

Comments

1
$query = "INSERT INTO blog_post (blah blah) VALUES ('$date',$article_clean', ...)";
                                                            ^

You have no opening quote for this argument. You need to add one.

On top of that, this statement looks suspicious:

$guid_clean = mysqli_real_escape_string ($dbc, $guid_clean);

All the others act on the "unclean" version to produce the clean one. Unless you've already set guid_clean somehow, it probably should be:

$guid_clean = mysqli_real_escape_string ($dbc, $guid);

As I say, that's not necessarily the case but I'd check it to make sure.

Comments

0

Try to get a better PHP IDE to get over these problems easily.

1 Comment

Eclipse is quite good. I am using PHPStorm now. There is a trial version available, you can give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.