Jump to content


Photo

mysql query not working.... need help desperately


  • Please log in to reply
2 replies to this topic

#1 ivalea

ivalea
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 16 October 2006 - 05:16 AM

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:

 <?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 '';
		}
  
?>


#2 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 16 October 2006 - 06:46 AM

hmmm... well first off your running the query, then running it again.
$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);

Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 joshi_v

joshi_v
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 16 October 2006 - 09:45 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users