Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

0- error? can't add new items or categories


JCrossfield

Recommended Posts

Posted

Hi All,

 

I'm having a weird issue that I'm hoping someone can help me troubleshoot.

 

I am unable to add new items or categories. When I try to add a new item in the admin panel, I get this weird error on a white screen:

 

0-

insert into products_to_categories (products_id, categories_id) values ('0', '29')

[TEP STOP]

 

 

So then I go back to the admin panel and look for the item I just tried to add, and it's not there. There is some ugly item (no picture or words, just a price) that shows up on my website though...when I click on it, it says "product not found".

 

I also tried adding new categories, and get the error message:

0 -

insert into categories_description (categories_name, categories_id, language_id) values ('Test', '0', '1')

[TEP STOP]

 

I do not see any result from this attempt in my admin panel or on the website.

 

Any ideas of what is going on here?

 

Thanks in advance! JEC

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Posted

couple of things you could try

 

in your catalog\includes\configure.php make sure persistent connections are off

define('USE_PCONNECT', 'false'); // use persistent connections?

 

using phpmyadmin check the categories sql table. Make sure the categories_id is set to auto increment for the extra column.

Posted

Hi enigma1-

 

I tried both of those things and they were both set as you described (persistent connections off and categories_id to auto increment on the extra column.

 

Thanks for your help. Any other ideas?

 

By the way, since my original post, I tried to see if restoring the original database might help...went back to the original sample db and I was still unable to add items or categories. Since, that didn't help, I restored back to newer version of the db. Would the fact that even the original db could not add items or categories suggest that it's something in the php code?

 

Thanks, Jeanie

 

 

couple of things you could try

 

in your catalog\includes\configure.php make sure persistent connections are off

define('USE_PCONNECT', 'false'); // use persistent connections?

 

using phpmyadmin check the categories sql table. Make sure the categories_id is set to auto increment for the extra column.

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Posted

maybe there is, have you made modifications to your catalog\admin\categories.php?

Posted

I don't think I made any changes to categories.php, but just in case I saved the original file catalog\admin\categories.php into my working directory and uploaded the original file to the server. Unfortunately, I still get the same error and cannot add new categories or products.

 

Any other ideas? I really appreciate your help in trying to track down the problem.

 

 

 

 

maybe there is, have you made modifications to your catalog\admin\categories.php?

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Posted

By the way, I've added two contributions to my site: the "current auctions v2.1 (english)" and "password_protection". Unfortunately, I don't know if the add new products or categories functioned properly before installing these features. Maybe the password_protection contrib did something to mess it up...I installed that feature because I don't have rights to set privileges on folders with my hosting service, so I installed that just in the admin folder, and put the access_control.php references in the admin\includes_top.php so that the password protection would cover ...but includes_top.php doesn't seem to be called in categories.php. Hmmm...I don't know if there might be a problem with one of these contributions.

 

 

I don't think I made any changes to categories.php, but just in case I saved the original file catalog\admin\categories.php into my working directory and uploaded the original file to the server. Unfortunately, I still get the same error and cannot add new categories or products.

 

Any other ideas? I really appreciate your help in trying to track down the problem.

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Posted

using phpmyadmin select the categories table then click the operations tab. What the auto_increment field shows there?

Posted

I'm not sure if this is the info you're asking about, but what I see in phpmyadmin, in the categories table, after clicking the operations tab:

Under "Table Options:"

66 auto_increment

Does that provide any insight?

 

If that's the next number to add, that sounds right...the other day I went into phpmyadmin and added a category straight into the database, and numbered it 65...then I went into the categories_description table and added a new row and assigned it to have category_id of 65.

 

********

Eureka! So, I just tried adding an item thru the admin panel again (to make sure it still wasn't working)...I see in browsing the categories table in phpmyadmin that it added 66 to the category table and in browsing the categories_description table it added a line in the categories_description table, but it did NOT set the categories_id in the categories_description for that line...well, actually it set it to "0". I manually set it to "66" and now it shows up!

 

*OK, so where do I fix it in the code so that when I create a new one in the admin panel, that it sets the categories_description table<categories_id to the number that it just setup in the categories table?

 

I bet you know the answer! Any more pointers would be greatly appreciated!

 

Thanks,

JEC

 

 

 

 

using phpmyadmin select the categories table then click the operations tab. What the auto_increment field shows there?

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Posted

Well the admin\categories.php file already does that.

 

In that file this code:

		  $categories_id = tep_db_insert_id();

obtains the new categories_id from the categories table. Then few lines later it assigns it for the categories_description for each of the languages.

		$languages = tep_get_languages();
	for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
	  $categories_name_array = $HTTP_POST_VARS['categories_name'];

	  $language_id = $languages[$i]['id'];

	  $sql_data_array = array('categories_name' => tep_db_prepare_input($categories_name_array[$language_id]));

	  if ($action == 'insert_category') {
		$insert_sql_data = array('categories_id' => $categories_id,
								 'language_id' => $languages[$i]['id']);

		$sql_data_array = array_merge($sql_data_array, $insert_sql_data);

		tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array);
	  } elseif ($action == 'update_category') {
		tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
	  }

 

you said you did try with the default oscommerce categories.php and you still had the same error. Are you using the default language? Anything special there?

Posted

Yeah, I'm using the default language and I can't think of anything noteworthy in that regard...it's just the default code in categories.php, I compared the code to what you posted here and it matches exactly (and I still can't add any new items or categories.)

What a mystery...any other ideas?

 

 

Well the admin\categories.php file already does that.

 

In that file this code:

		  $categories_id = tep_db_insert_id();

obtains the new categories_id from the categories table. Then few lines later it assigns it for the categories_description for each of the languages.

		$languages = tep_get_languages();
	for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
	  $categories_name_array = $HTTP_POST_VARS['categories_name'];

	  $language_id = $languages[$i]['id'];

	  $sql_data_array = array('categories_name' => tep_db_prepare_input($categories_name_array[$language_id]));

	  if ($action == 'insert_category') {
		$insert_sql_data = array('categories_id' => $categories_id,
								 'language_id' => $languages[$i]['id']);

		$sql_data_array = array_merge($sql_data_array, $insert_sql_data);

		tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array);
	  } elseif ($action == 'update_category') {
		tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
	  }

 

you said you did try with the default oscommerce categories.php and you still had the same error. Are you using the default language? Anything special there?

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Posted

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Posted

Thanks enigma1 and Monika for all your assistance.

 

The problem is fixed!

 

The post Monika mentioned led me to this post:

http://www.oscommerce.com/forums/index.php?sho...mp;#entry240552

 

It took me a while to figure out exactly what they meant in these posts and where to make the changes...so I thought I'd post the solution here for the next person who has this problem.

 

There are 2 places you need to replace a line of code:

admin\includes\functions\database.php ----> around line 114

includes\functions\database.php ----> around line 110

 

In both files, it's the same...

Change:

function tep_db_insert_id() {

return mysql_insert_id();

}

 

To:

function tep_db_insert_id( $link = 'db_link') {

global $$link;

return mysql_insert_id($$link);

}

 

 

Best Wishes!

Jeanie

 

 

Jeanie Crossfield

Bear River Web Design

Auburn, CA

You Have Options...Choose Local!

www.BearRiverWebDesign.com

Archived

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

×
×
  • Create New...