DanDigital Posted November 14, 2007 Share Posted November 14, 2007 Hi All, Could somebody check the code below for me for any obvious mistakes... I've been over and over it and whilst I don't get any errors an the function resloves, nothing gets written to my DB. Any help greatly appreciated.. Dan <?php function addItem($object_id, $type, $qty = 1) { global $database; if (!$this->itemExists($object_id, $type)) { $curr_id = $this->getNoOfItems(); $this->_items[$curr_id] = new lightbox_item($object_id, $type, $qty); $database->setQuery("INSERT INTO #__users (recordbox) VALUES ('test') WHERE id='63'"); return true; } else { return false; } } ?> Quote Link to comment Share on other sites More sharing options...
nloding Posted November 14, 2007 Share Posted November 14, 2007 Please wrap your code in the CODE tags (the '#' button) to make it easier to read. Please also include the rest of your code, for instance the database object, and rest of this object (itemExists, getNoOfItems) and whatever lightbox_item is too probably. Another idea is to echo "step 1" then "step 2" for each step so you see if part fails. Especially after the 'else' command, so you can see if the if statement is true or not. Quote Link to comment Share on other sites More sharing options...
448191 Posted November 14, 2007 Share Posted November 14, 2007 There doesn't seem to be anything functionally wrong with the code you posted. I have to debate you choice of using global instances though. Unless you like your code hard to maintain, understand and debug... Quote Link to comment Share on other sites More sharing options...
emehrkay Posted November 15, 2007 Share Posted November 15, 2007 is this a valid query? "INSERT INTO #__users (recordbox) VALUES ('test') WHERE id='63'" Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted November 15, 2007 Share Posted November 15, 2007 is this a valid query? "INSERT INTO #__users (recordbox) VALUES ('test') WHERE id='63'" The setQuery() method might replace it with something else. Perhaps he has a list of table names and their corresponding "codes". That's the only explanation I see. Quote Link to comment Share on other sites More sharing options...
Evan69 Posted November 22, 2007 Share Posted November 22, 2007 yeah, apart from the query everything looks good. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted November 22, 2007 Share Posted November 22, 2007 is this a valid query? "INSERT INTO #__users (recordbox) VALUES ('test') WHERE id='63'" The setQuery() method might replace it with something else. Perhaps he has a list of table names and their corresponding "codes". That's the only explanation I see. Ah... I didn't see what you meant. I thought you meant the table name You cannot have a WHERE clause in an INSERT. See: http://dev.mysql.com/doc/refman/5.0/en/insert.html That's probably the problem. Quote Link to comment Share on other sites More sharing options...
DyslexicDog Posted November 23, 2007 Share Posted November 23, 2007 is this a valid query? "INSERT INTO #__users (recordbox) VALUES ('test') WHERE id='63'" The setQuery() method might replace it with something else. Perhaps he has a list of table names and their corresponding "codes". That's the only explanation I see. Ah... I didn't see what you meant. I thought you meant the table name You cannot have a WHERE clause in an INSERT. See: http://dev.mysql.com/doc/refman/5.0/en/insert.html That's probably the problem. I believe you are looking for the UPDATE portion of sql ie. <?php $sql = "UPDATE #__users SET recordbox = 'test' WHERE id=63"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.