-1

im trying to insert some data into a table, mysql gives syntax error and i cant find, may i get help please

INSERT INTO museums(id,name,rate,phone,opening_hours,closing_hours,location,image)
VALUES(1,"The Royal Automobile Museum",4.7,065411392,10:00:00, 7:00:00,"At Tibbiyya, Amman",LOAD_FILE('C:\xampp\htdocs\wael\images\The Royal Automobile Museum.jpg'));
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':00:00, 7:00:00,"At Tibbiyya, Amman",LOAD_FILE('C:\xampp\htdocs\wael\images\T...' at line 2
  • 3
    Can you post a database scheme? I suspect your `opening/closing hours` are strings? There you have an error.. Maybe put `"10:00:00"` – DrummerMann Jan 09 '22 at 21:36
  • data types or size of column doesnt fit the sample data probably. please have a look museum table and compare with data which you want to insert – Yusuf Jan 09 '22 at 21:38
  • yep, the time need to be inside double quotes, but still doesn't insert image, it gives me error " image can't be null" – aasem shoshari Jan 09 '22 at 21:46
  • These might be helpful. [How to use LOAD_FILE to load a file into a MySQL blob?](https://stackoverflow.com/questions/8229951/how-to-use-load-file-to-load-a-file-into-a-mysql-blob) and [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – steven7mwesigwa Jan 09 '22 at 22:33
  • @aasemshoshari . For *"Column 'image' cannot be null" error* possible solution... [How to insert BLOB and CLOB files in MySQL?](https://stackoverflow.com/a/57113148/7376590) – steven7mwesigwa Jan 09 '22 at 22:45

2 Answers2

0

try this one:

INSERT INTO museums (id,name,rate,phone,opening_hours,closing_hours,location,image) VALUES (1,'The Royal Automobile Museum',4.7,065411392,'10:00:00','7:00:00','At Tibbiyya, Amman','LOAD_FILE(''C:\xampp\htdocs\wael\images\The Royal Automobile Museum.jpg'')');

It gives error probably due to ' mark before C:/// and after jpg. so you need to change it to '' instead of '

Yusuf
  • 192
  • 5
0

use ' for hours and phone

insert into museums
    (
       id
     , name
     , rate
     , phone
     , opening_hours
     , closing_hours
     , location
     , image
    )
    values
    (1
    , 'The Royal Automobile Museum'
    , 4.7
    , '065411392'
    , '10:00:00'
    , '7:00:00'
    , 'At Tibbiyya, Amman'
    , LOAD_FILE('C:\xampp\htdocs\wael\images\The Royal Automobile Museum.jpg'))