Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

tep_db_insert_id()


omario

Recommended Posts

So I've been having problems with my OSC. Firstly my orders would never show up in the admin center, and then I realized my product reviews would never actually show themselves on the review page. I did a little investigating and I foiund out it's because the tep_db_insert_id() functino which calls mysql_insert_id() always, no matter what, returns zero. Does anyone have any ideas why this could be, AND how I could fix it? Please help as I've been working on this for days now without success.

 

Thanks in advance

 

- Shoeb Omar

Link to comment
Share on other sites

Edit: This was directed to Johnson, I'm trying enigma's response now.

 

how do you mean?

 

For example this is what is currently happening:

 

Add record to table orders

$insertid = tep_db_insert_id();

echo $insertid;

 

Instead of $insertid being the last auto incremented value for table orders, it will be 0.

 

From the manual this means that the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call mysql_insert_id() immediately after the query that generates the value.

 

However, I am calling it immediately after, because that's what's in the default OSC code. Therefore, why is is returning zero still?

 

- Shoeb

Link to comment
Share on other sites

However, I am calling it immediately after, because that's what's in the default OSC code.  Therefore, why is is returning zero still?

 

- Shoeb

 

There is something wrong with the query - nothing is inserted.

 

Matti

Link to comment
Share on other sites

According to the database though, it is. I check and the record gets added to the database. What's more, if I change the code to use LAST_INSERT_ID() form MySQL, the correct record is returned also

Link to comment
Share on other sites

what happens if:

1. Create a new customer account (this will use your catalog end)

2. Create a new test product. (this will use your admin part)

 

Do you get the same problem?

Link to comment
Share on other sites

Additionally, I just took this from logging of the MySQL queries:

 

QUERY insert into reviews (products_id, customers_id, customers_name, reviews_rating, date_added) values ('53', '8296', 'Shoeb Omar', '5', now())

RESULT 1

QUERY insert into reviews_description (reviews_id, languages_id, reviews_text) values ('0', '1', 'this is a test review and hopefully the page parse time log thingy will give me some information on what\'s going on.')

 

The code in the file is:

 

      tep_db_query("insert into " . TABLE_REVIEWS . " (products_id, customers_id, customers_name, reviews_rating, date_added) values ('" . (int)$HTTP_GET_VARS['products_id'] . "', '" . (int)$customer_id . "', '" . tep_db_input($customer['customers_firstname']) . ' ' . tep_db_input($customer['customers_lastname']) . "', '" . tep_db_input($rating) . "', now())");
     $insert_id = tep_db_insert_id();

     tep_db_query("insert into " . TABLE_REVIEWS_DESCRIPTION . " (reviews_id, languages_id, reviews_text) values ('" . (int)$insert_id . "', '" . (int)$languages_id . "', '" . tep_db_input($review) . "')");

 

From this you can see everything seems ot be working as intended but the mysql_insert_id isnot returning the correct value.

 

Am I missing something?

 

Edit: Testing your suggestion enigma

Link to comment
Share on other sites

you have your store on a localhost too? if you could set it up locally at least you can rule out latencies, multi-access problems etc.

Link to comment
Share on other sites

well then I guess you have already tried to restart the apache etc. and you should have the default oscommerce store setup. Does the same thing happens there?

Link to comment
Share on other sites

well then I guess you have already tried to restart the apache etc. and you should have the default oscommerce store setup. Does the same thing happens there?

 

yeh..

 

It works on a default installation - that's one of the things that is so puzzling. I'm trying to compare database tables but I'm not finding any differences. Any ideas what I should look for?

Link to comment
Share on other sites

language_id? made any changes there from the default store? because all of these queries to insert records do check for it. And I vaguely remember when I was changed them had problems accessing the dbase.

Link to comment
Share on other sites

I'll have a look heh. The odd thing is I replaced my orders table with a fresh copy and that solved problems with orders. However, product reviews still has a problem even with fresh tables, so I must have some errant modification somewhere. This sure is frustrating though.

 

Thanks a ton for your help guys

Link to comment
Share on other sites

I understand that Matti, and I'm not making multiple connections. Oddly enough, although replacing the tables worked on my loclhost computer, replacing them online didn't change anything at all. any ideas?

 

- Shoeb

Link to comment
Share on other sites

  • 4 years later...

Hi all,

 

I don't usually like to reply to 5 year old posts, but I've just run up against exactly the same problem that omario had. I'll describe the problem and would appreciate any insight.

 

Up until 10pm last night, our oscommerce store had been running smoothly with no problems. What happened after the completion of the last successful order at 10pm, I don't know. We did not make any changes and neither did our web hosting provider.

 

But, the "orders_id" stopped being saved to the appropriate fields in "orders_total", "orders_products", and "orders_status_history" tables (A zero "0" is being inserted into these tables). The correct, auto incremented "orders_id" is still being inserted properly into the "orders" table. The remaining data is also being properly saved in the "orders_total", "orders_products", and "orders_status_history" tables.

 

So, it seems that something is happening between the following two statements in checkout_process.php:

 

tep_db_perform(TABLE_ORDERS, $sql_data_array);

$insert_id = tep_db_insert_id();

 

But what?

 

Any help would be greatly appreciated. Thanks!

 

Regards,

 

Gregory Bender

Link to comment
Share on other sites

Aha!

 

Fixed it.

 

I'd been working on my local copy of the files all day and decided to download the entire version of the oscommerce install and do a file comparison. (duh, should've done that hours ago)

 

Somehow code *had* gotten inserted between those lines (see my post above). So, the fix was obvious. Remove that code and go on with life.

 

How did that code get in there? I haven't a clue. Unless it happens again, I'm leaving that answer hanging...

 

Hope my little problem helps someone else.

 

Regards,

 

Gregory Bender

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...