76237

Table named 'like' in MySQL

Question:

I didn't realize 'like' was a keyword in SQL when I built my table. Now I get an error when I try insert into the row because 'like' is a SQL keyword.

<em>error: 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 VALUES (DEFAULT, NOW(), 'kirkins@gmail.com', '12345678')' at line 1</em>

Can I modify my insert to specify that I mean the table named like and not the like keyword?

$sql = "INSERT INTO like VALUES (DEFAULT, NOW(), '$email', '$post_id')";

Answer1:

Try it like this:

$sql = "INSERT INTO `like` VALUES (DEFAULT, NOW(), '$email', '$post_id')";

Answer2:

Escape the table name with ticks:

$sql = "INSERT INTO `like` VALUES (DEFAULT, NOW(), '$email', '$post_id')";

Recommend

  • Available pagefile size / virtual memory
  • how access value of array list on Struts framework by properties file
  • Using python to determine if a timestamp is under daylight savings time
  • link library to all targets in cmake project
  • How to move axis labels automatically in rgl R
  • Any command in mysql equivalent to Oracle's autotrace for performance turning
  • JPA CDI Injecting DAO into an Entity
  • Getting syntax error in mysql-php. You have an error in your SQL syntax;
  • Vigenere cipher not working
  • Swift Initialization Rule Confusion
  • ZipList with Scalaz
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • Question about instantiating object
  • Suppressing passwd when calling sqlplus from shell script
  • Security issues with PHP's Readfile method
  • pyodbc doesn't report sql server error
  • Email verification using google app script and google forms
  • Moving mysql files across servers
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Retrieving value from sql ExecuteScalar()
  • Splitting given String into two variables - php
  • PHP - How to update data to MySQL when click a radio button
  • Counter field in MS Access, how to generate?
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Check if a string to interpolate provides expected placeholders
  • How to check if every primary key value is being referenced as foreign key in another table
  • Do I've to free mysql result after storing it?
  • Unanticipated behavior
  • Comma separated Values
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • Can't mass-assign protected attributes when import data from csv file
  • Unable to use reactive element in my shiny app
  • playing video using jmf