adders Posted June 19, 2007 Share Posted June 19, 2007 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 More sharing options...
chigley Posted June 19, 2007 Share Posted June 19, 2007 $thule_products_id_query = mysql_query($thulequery) or die(mysql_error()); // <-- use that Link to comment https://forums.phpfreaks.com/topic/56239-help-with-sql-query-in-php/#findComment-277771 Share on other sites More sharing options...
adders Posted June 19, 2007 Author Share Posted June 19, 2007 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 Link to comment https://forums.phpfreaks.com/topic/56239-help-with-sql-query-in-php/#findComment-277778 Share on other sites More sharing options...
chigley Posted June 19, 2007 Share Posted June 19, 2007 Try this: $thulequery="SELECT products_id FROM products WHERE products_model = '{$thule_products_model}'"; Link to comment https://forums.phpfreaks.com/topic/56239-help-with-sql-query-in-php/#findComment-277780 Share on other sites More sharing options...
adders Posted June 19, 2007 Author Share Posted June 19, 2007 Hello Chigley You are a Genius. That worked a treat, once I corrected a variable name I'd misspelled. Thanks a million for your help. Cheers Paul Link to comment https://forums.phpfreaks.com/topic/56239-help-with-sql-query-in-php/#findComment-277813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.