0

I have ths query, again i'm trying to pass from pop3 account to mysql database:

mysqli_query($con,"INSERT INTO procesa_emails (body_mail, uid_message, fecha, from, to, subject, message_id) VALUES ('".mysqli_real_escape_string($con,htmlentities(str_replace("'","",str_replace('"','',$message))))."','".mysqli_real_escape_string($con,htmlentities($uid_mess))."','".mysqli_real_escape_string($con,htmlentities($fecha))."','".mysqli_real_escape_string($con,htmlentities($from))."','".mysqli_real_escape_string($con,htmlentities($to))."','".mysqli_real_escape_string($con,htmlentities($subject))."','".mysqli_real_escape_string($con,htmlentities($mui))."')")or die(mysqli_error($con));

But It returns me:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, subject, message_id) 

I tried with str_replace("'","",str_replace('"'.'')) But It also doesn't work

Darkness
  • 101
  • 1
  • 13
  • May be a silly question, but did you maybe mispell `procesa_emails`? Maybe `process_emails`? – Funk Forty Niner Jul 24 '13 at 20:58
  • procesa_emails is the database name – Darkness Jul 24 '13 at 20:59
  • ok, just thought I'd ask. The `s` and `a` are next to each other on the keyword, one never knows. – Funk Forty Niner Jul 24 '13 at 20:59
  • From and to may be reserved keywords in mysql. Add backticks around your field names, that'll eliminate that. For e.g: `from`, `to` - its always considered good practice to do that anyway. Good habit to get into! – laminatefish Jul 24 '13 at 21:00
  • Ok, yes, well, i speak spanish, emmm and process in spanish is procesa or procesar xD – Darkness Jul 24 '13 at 21:00
  • 1
    @Darkness Si, no problema amigo ;-) – Funk Forty Niner Jul 24 '13 at 21:01
  • @LokiSinclair i tried: INSERT INTO procesa_emails (body_mail,uid_message,fecha,from,to,subject,message_id) but it also returns: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from,to,subject,message_id) VALUES ('ESTIMADO GUILLERMO\r\n\r\nBUENA TARDE\r\n\r' at line 1 – Darkness Jul 24 '13 at 21:02
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – michaelb958--GoFundMonica May 07 '14 at 00:16

1 Answers1

1

FROM is a reserved keyword. So, if you want to use that inside your query, you need to wrap it in backticks, like so:

mysqli_query($con,"
INSERT INTO procesa_emails (body_mail, uid_message, fecha, `from`, ...

Hope this helps!

Amal Murali
  • 75,622
  • 18
  • 128
  • 150