0

I am using phpMyadmin as a database and I can't drop the tables ...how to spot the syntax error?

<?php       
include 'dbconnect.php';  //connect to DB  
//Droping The tables  
$dropping = @mysql_query('DROP TABLE IF EXISTS rents, criticise, writesIn, writenIn, translated, reads, worksIn, inStock, playsIN, store, genre, employee, newspaper, customer, critic, language, actor, film, city ;'); 
if (!$dropping) {   
  exit('<p>Error dropping the tables<br />'.   
      'Error: ' . mysql_error() . '</p>');   
}       
if ($dropping) {   
  echo 'everything went just fine dropping the tables<br>';   
}
3
  • 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 'reads,worksIn,inStock,playsIN,store,genre,employee,newspaper,customer,critic,lan' at line 1 Commented Apr 9, 2015 at 10:08
  • 1
    phpMyadmin as a database no phpmyadmin is not a database! try to understand what you did on php and sql (and no, its not the same!) Commented Apr 9, 2015 at 10:09
  • remove semicolon from city ;'); Commented Apr 9, 2015 at 10:10

2 Answers 2

1

reads is a reserved MySQL keyword. You need to enclose it in backticks:

DROP TABLE IF EXISTS rents, criticise, writesIn, writenIn, translated, `reads`, worksIn, inStock, playsIN, store, genre, employee, newspaper, customer, critic, language, actor, film, city
Sign up to request clarification or add additional context in comments.

Comments

0
$dropping = @mysql_query('DROP TABLE IF EXISTS rents, criticise, writesIn, writenIn, translated, `reads`, worksIn, inStock, playsIN, store, genre, employee, newspaper, customer, critic, language, actor, film, city  '); 

remove the semicolon ; and use backticks for reads as its a keyword

1 Comment

Semicolon is a delimiter which will not cause any error at the end;

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.