Jump to content

Please check my Code!!


DanDigital

Recommended Posts

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;
	}
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.