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
https://forums.phpfreaks.com/topic/77311-please-check-my-code/
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
https://forums.phpfreaks.com/topic/77311-please-check-my-code/#findComment-391594
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
https://forums.phpfreaks.com/topic/77311-please-check-my-code/#findComment-396653
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
https://forums.phpfreaks.com/topic/77311-please-check-my-code/#findComment-397687
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.