Jump to content

mysql query not working.... need help desperately


ivalea

Recommended Posts

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.