-1

guys, I have problem with inserting new row:

mysql_connect("localhost", "abc", "sdvs") or die(mysql_error());
mysql_select_db("abc") or die(mysql_error());
mysql_query("INSERT INTO like (IP) VALUES ('".$_SERVER['REMOTE_ADDR']."')") or die(mysql_error());

I get

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 'like ('84.46.249.124')' at line 1

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Stuneris
  • 77
  • 2
  • 12
  • 1
    Seriously; you could have Google'd this. – Funk Forty Niner Mar 10 '17 at 14:26
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Mar 10 '17 at 14:27

1 Answers1

0

You need to wrap your field name like, it reserved by MySQL:

mysql_query("INSERT INTO `like` (IP) VALUES ('".$_SERVER['REMOTE_ADDR']."')") or die(mysql_error());
TheMY3
  • 353
  • 3
  • 10