Jump to content

Help with SQL query in PHP


adders

Recommended Posts

Hello All the code snippet below is from an osCommerce store I'm adding some extra functionality to.

 

It's failing at this line $thule_products_id = mysql_result($thule_products_id_query,0); with this error:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/faster/internal/http/www1/includes/application_top.php on line 388

 

Warning: Cannot modify header information - headers already sent by (output started at /home/faster/internal/http/www1/includes/application_top.php:388) in /home/faster/internal/http/www1/includes/functions/general.php on line 28

 

Does anyone know what is going wrong, I've also posted on the osCommerce forum but am still awaiting a reply so thought I'd ask you guys.

 

Here's the code.

 

	 // customer adds a product from the Thule Database
      case 'add_product_thule' :    if (isset($HTTP_POST_VARS['products_model'])) {
  							$tule_products_model = $HTTP_POST_VARS['products_model'];
							$thulequery="SELECT products_id FROM products WHERE products_model = $thule_products_model";
							$thule_products_id_query = mysql_query($thulequery);
							$thule_products_id = mysql_result($thule_products_id_query,0);
  							
                                $cart->add_cart($thule_products_id, $cart->get_quantity(tep_get_uprid($thule_products_id, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;

 

Thanks

 

Paul

Link to comment
https://forums.phpfreaks.com/topic/56239-help-with-sql-query-in-php/
Share on other sites

Hey thanks for the quick reply Chigley.

 

I just added your line of code, I now get this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

My code now looks like this:

// customer adds a product from the Thule Database
      case 'add_product_thule' :    if (isset($HTTP_POST_VARS['products_model'])) {
  							$tule_products_model = $HTTP_POST_VARS['products_model'];
							$thulequery="SELECT products_id FROM products WHERE products_model = $thule_products_model";
							$thule_products_id_query = mysql_query($thulequery) or die(mysql_error());
							$thule_products_id = mysql_result($thule_products_id_query,0);
  							
                                $cart->add_cart($thule_products_id, $cart->get_quantity(tep_get_uprid($thule_products_id, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;

 

Cheers

 

Paul

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.