ivalea Posted October 16, 2006 Share Posted October 16, 2006 I'm working with oscommerce and created a table called students. We have one product that is actually a course. Once a customer purchases this course, it's supposed to add them to the students table. On the checkout success page I first did a select statement that is supposed to look at the order just made and see if the product model matches the one of the course. If, and ONLY if it does, then select the customers email address from the customers table and add them to the students table along with their customer id. If the product model of the item just purchased doesn't match then do absolutely nothing. I've tried this over and over again and I cannot seem to get it to act right. Either all purchases are added to the students table or none at all whether they've purchased the correct product or not. i'm ashamed to admit it, but I've been trying to get this small piece to work for a week now.... ???Any help on this would be sooooo appreciated. Please note that where it says "INSERT CUSTOMERS ID HERE" in the insert statement - this is because I was unsure of where and how to get the customers email from the customers table. Here is my code:[code] <?php $model_query = mysql_query("select products_model from orders_products where orders_id = '" . (int)$orders['orders_id'] . "' and products_model = 'CBT-0100'"); $result = mysql_query($mod_query); if($result){ $studentsquery = mysql_query("insert into students (students_id, customers_id, students_pmodel, students_email, students_mod1, students_mod2, students_mod3, students_manual, students_cert) values ('', '" . (int)$customer_id['customers_id'] . "', 'CBT-0100', 'INSERT - CUSTOMER ID HERE', '', '', '', '', '')"); }else{ echo ''; } ?>[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 16, 2006 Share Posted October 16, 2006 hmmm... well first off your running the query, then running it again.[code]$model_query = mysql_query("select products_model from orders_products where orders_id = '" . (int)$orders['orders_id'] . "' and products_model = 'CBT-0100'");$result = mysql_query($mod_query);[/code] Quote Link to comment Share on other sites More sharing options...
joshi_v Posted October 16, 2006 Share Posted October 16, 2006 Why we u r using mysql_query two times?try this$model_query = "select products_model from orders_products where orders_id = '" . (int)$orders['orders_id'] . "' and products_model = 'CBT-0100' ";$result = mysql_query($model_query) or die (mysql_error());if($result){$studentsquery = mysql_query("insert into students (students_id, customers_id, students_pmodel, students_email, students_mod1, students_mod2, students_mod3, students_manual, students_cert) values ('', '" . (int)$customer_id['customers_id'] . "', 'CBT-0100', 'INSERT - CUSTOMER ID HERE', '', '', '', '', '')") or die (mysql_error());}else{ echo '';}If still u have errors , print the query (echo $model_query) on browser and copy the query.then execute the same query in db ,see the errors what it is showing.Happy Coding! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.