Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Use of ereg() in 'add product'


alverman

Recommended Posts

Can somebody explain to me why the use of the function ereg() in

 case 'add_product' :    if (ereg('^[0-9]+$', $HTTP_POST_VARS['products_id']))

in application_top.php.

 

Not much PHP but I think it requires that string " $HTTP_POST_VARS['products_id']" is composed from the beginning ^ to the end $ by numbers 0-9 and nothing else :?:

 

I need to pass a complete "Product id" like 211{6}116{1}115.

It works if I do someting like this: ereg('^[0-9{}]+$', ... but what's beyond :oops: .

 

Thank you

 

ivan

Link to comment
Share on other sites

Thank you Christian for the prompt answer,

since PHP is still kinda "black magic" to me, I was wondering if there's a reason for restricting to 0-9 the possible values to be passed to the function.

 

thanx

 

ivan

Link to comment
Share on other sites

We only want numeric values to appear here, hence the ereg.

 

HTH

You can't have everything. That's why trains have difficulty crossing oceans, and hippos did not adapt to fly. -- from the OpenBSD mailinglist.

Link to comment
Share on other sites

Too bad you guys decided to answer my question .... now you can't get rid of me :D

What I'm trying to accomplish here is to add the possibility of modifying an item that's already in the cart.

Some carts allow that and some users here requested for it ( http://www.oscommerce.com/forums/viewtopic.php?t=32435 )

I put togheter some lines of code (do not laugh, please) and everythig works properly. At a certain point of the story I come across w/ the "add product" switch case and have to mod it this way :

      // customer adds a product from the products page  //

     case 'add_product' :    if (ereg('^[0-9{}]+$', $HTTP_POST_VARS['products_id'])) {



///------------------------------ mod start



                               if ($HTTP_POST_VARS['modify_cart']) {

                                 $cart->remove($HTTP_POST_VARS['products_id']);

                                 $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+ $HTTP_POST_VARS['cart_quantity'],  $HTTP_POST_VARS['id']);

                                 tep_redirect(tep_href_link($goto, '', 'NONSSL'));

                                 break;

                                 }

                                else {



///-----------------------------mod end



                               $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+ $HTTP_POST_VARS['cart_quantity'], $HTTP_POST_VARS['id']);

                               }

                             }

                             tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters), 'NONSSL'));

                             break;

and to perform $cart->remove($HTTP_POST_VARS['products_id']);

 

I need to pass the whole "211{6}116{1}115" , numeric values + {} otherwise that specific item will not be recognized and removed,

hence : ereg('^[0-9{}]+$', $HTTP_POST_VARS['products_id']).

Of course there will be a more elegant way to perform this task but I'd like to know your opinion on modifying the func this way.

 

Thank you

ivan

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...