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:
$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);
$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', '', '', '', '', '')");