Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: MySQL Error 1054

  1. #1
    dprimedx's Avatar
    dprimedx is offline Newbie
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    MySQL Error 1054

    I'm working on a billing & records system for a local NPO and I'm having some trouble with the database. I have a good deal of experience with MySQL and SQL Server 2005/2008 databases, but I just can't seem to get rid of this error 1054.

    I've spent some time on Google and most of the results seem to be talking about this occurring in phpMyAdmin or some other piece of web based software, however, I'm using the MySQL prompt on my Linux box.

    I have a trigger set up on the 'billing' table that should calculate the total fee based on the amount of time spent (used to calculate units) and the price per unit (stored in another table). Its my first time writing up a trigger, so I may have done something wrong with it.

    The problem occurs when I insert a row into 'billing'. It gives me an error 1054 saying "Unknown column 'units' in 'field list'".

    As there are a few related files, I've uploaded them to one of my sites and I will link to them near the end of the post.

    The insert query I use is:
    Code:
    INSERT INTO billing (idc,EI,school,funding_source,serviceDate,totalTime,therapistID,mileage,serviceTypeID) values(0,'M','BAHS','BA','10-29-2008',27,0,0,0);
    The files are all located in the following directory, if you'd rather me copy/paste them here, I have no issue with doing that. (I'd link to it, but I have < 10 posts)
    davidrware.com/code/sql/

    Thanks for the help and for taking the time to look this over for me. If you need any more information, just let me know.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: MySQL Error 1054

    What is the exact error?

    Try putting the column names in the `(backtick) that usually helps me.

  4. #3
    dprimedx's Avatar
    dprimedx is offline Newbie
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Re: MySQL Error 1054

    The error:
    Error 1054 Unknown column 'units' in 'field list'
    It occurs whenever I try an insert on 'billing'.

    I tried the insert with the backticks around the column names but I'm still receiving the same error.

  5. #4
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: MySQL Error 1054

    INSERT INTO billing (idc,EI,school,funding_source,serviceDate,totalTim e,therapistID,mileage,serviceTypeID) values(0,'M','BAHS','BA','10-29-2008',27,0,0,0);
    i cant find "units" field here, can you post the query you are trying to run?
    yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  6. #5
    dprimedx's Avatar
    dprimedx is offline Newbie
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Re: MySQL Error 1054

    Quote Originally Posted by amrosama View Post
    i cant find "units" field here, can you post the query you are trying to run?
    The insert query is the one I'm trying to run. It shouldn't be adding in a value for units. The value for units should be calculated by the trigger.

  7. #6
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: MySQL Error 1054

    What's the trigger?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    dprimedx's Avatar
    dprimedx is offline Newbie
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Re: MySQL Error 1054

    Quote Originally Posted by WingedPanther View Post
    What's the trigger?
    Code:
    USE care1;
    
    DELIMITER $$
    CREATE TRIGGER billing_units
    	 BEFORE INSERT ON billing
    	 FOR EACH ROW
    BEGIN
    	DECLARE tt INTEGER;
    	DECLARE tmod DECIMAL(5,2);
    	DECLARE price DECIMAL(5,2);
    
    	SELECT totalTime INTO tt FROM billing WHERE idb = NEW.idb;
    	SET tmod = MOD(tt,15);
    	IF tmod = 0 THEN
    		SET NEW.units = tmod/15;
    	ELSE
    		SET NEW.units = (tt+(15-MOD(tt,15)))/15;
    	END IF;
    	
    	SELECT cpu INTO price FROM services WHERE services.ids = NEW.serviceTypeID;
    
    	SET NEW.totalFee = units*price;
    END$$

  9. #8
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: MySQL Error 1054

    I think that may be your problem. units isn't a field in NEW (based on the insert statement), so it fails when you try to access NEW.units.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  10. #9
    dprimedx's Avatar
    dprimedx is offline Newbie
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Re: MySQL Error 1054

    Code:
    USE care1;
    
    DELIMITER $$
    CREATE TRIGGER billing_units
    	 BEFORE INSERT ON billing
    	 FOR EACH ROW
    BEGIN
    	DECLARE tt INTEGER;
    	DECLARE tmod DECIMAL(5,2);
    	DECLARE price DECIMAL(5,2);
    
    	SELECT totalTime INTO tt FROM billing WHERE idb = NEW.idb;
    	SET tmod = MOD(tt,15);
    	IF tmod = 0 THEN
    		-- SET NEW.units = tmod/15;
    		UPDATE billing SET units = tmod/15 WHERE idb = NEW.idb;
    	ELSE
    		-- SET NEW.units = (tt+(15-MOD(tt,15)))/15;
    		UPDATE billing SET units = ((tt+15-MOD(tt,15)))/15 WHERE idb = NEW.idb;
    	END IF;
    	
    	SELECT cpu INTO price FROM services WHERE services.ids = NEW.serviceTypeID;
    
    	SET NEW.totalFee = units*price;
    END$$
    There's my new trigger. I no longer get the previous error, but now I'm getting Error 1442: Can't update 'billing' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

    Any ideas on this new one? The insert statement is the same as above.

  11. #10
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: MySQL Error 1054

    Have you considered changing your trigger to AFTER INSERT so it can issue an update statement against the affected row?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Custom MySQL Error [HELP]
    By bbqroast in forum PHP Development
    Replies: 4
    Last Post: 04-13-2011, 10:04 AM
  2. SQL syntax error in MySQL
    By tomitzel in forum Database & Database Programming
    Replies: 2
    Last Post: 04-10-2010, 03:10 AM
  3. MYSQL INSERT Error
    By dunila in forum PHP Development
    Replies: 2
    Last Post: 08-25-2009, 02:33 AM
  4. error in MySQL query
    By Orjan in forum Database & Database Programming
    Replies: 2
    Last Post: 05-22-2008, 05:21 PM
  5. Mysql Error
    By Whitey in forum PHP Development
    Replies: 5
    Last Post: 03-05-2008, 02:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts