4

I have this problem: If I write the following query:

INSERT INTO prodotto  (Barcode, InseritoDa,  DataInserimento, UrlImage) 
VALUES  ('vfr','ff','12-10-2012', 'vfr.jpg')    

I get this error message:

Error Code: 1054. Unknown column 'InseritoDa' in 'where clause'

But in the table prodotto i have this column and its name InseritoDa.

Where am I wrong? the error may be due to the fact that the field InseritoDa is a foreign key that points to another table called utente?

the trigger associated to the table is:

-- Trigger DDL Statements
DELIMITER $$

USE `m4af`$$

CREATE
DEFINER=`root`@`localhost`
TRIGGER `m4af`.`IncrementaProdottiInseritiUtente`
AFTER INSERT ON `m4af`.`prodotto`
FOR EACH ROW
update utente as u
set ProdottiInseriti= (select ProdottiInseriti from utente where username= InseritoDa)+1
where u.username = InseritoDa$$
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
Martina
  • 1,852
  • 8
  • 41
  • 78
  • 1
    Do you have triggers defined on that table? – rs. Oct 12 '12 at 15:13
  • 1
    Have you checked the exact spelling and upper/lowercase for that column? Maybe post a screenshot or the `CREATE TABLE` command of that table. – Sirko Oct 12 '12 at 15:14

1 Answers1

4

Since the error states that it occurred in a WHERE clause there might be an insert-trigger that executes another query and fails. There is no WHERE clause in your insert statement.

Edit

Try to edit your INSERT trigger like this:

update utente
set ProdottiInseriti = ProdottiInseriti + 1
where username = NEW.InseritoDa
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • Please show your trigger statement. There is most probably an error in it. – juergen d Oct 12 '12 at 15:15
  • 2
    In your trigger you use a column called `InseritoDa` in table `utente`. Does that table have such a column? – juergen d Oct 12 '12 at 15:20
  • no, the coloumn InseritoDa is only in the table prodotto but the trigger is called after one insert in to that table so I thought of using it. So, how do I change the trigger? – Martina Oct 12 '12 at 15:22
  • What are you trying to do in the trigger? I'm not sure what you want to achive. – juergen d Oct 12 '12 at 15:23
  • I would like to increase the field prodottiInseriti in the table utente each time it is inserted a product in the table prodotto on the basis of the field inseritoDa. – Martina Oct 12 '12 at 15:28