[Skip to main content](#vessel-content)

#   Run a query after order is confirmed..

##

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago [\#26786](#26786) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  *[Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26786 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")* was created by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")*

Hi,

I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:

I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.

As mentioned, I have little coding experience but any samples/exmaples should help me to get started..

Thanks in advance ![:)](/media/kunena/emoticons/3.png ":)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

15 years 1 month ago [\#26805](#26805) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26805 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

Hi,

You should look at the history plugin which is installed by default with HikaShop, in the file plugins/hikashop/history.php
It implements the onAfterOrderUpdate event to add history information to orders.
There is also a query run in the onAfterOrderDelete event so you can see how queries are run.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago [\#26899](#26899) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26899 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

Hi Nicolas,

thanks for the pointer. With my limited knowledge, I have put together the below. Seems to be working but I can't seem to get the email address, it comes up blank. Any idea why? Also, I want to only run the query if the product id is 1, 5 or 7 how do I do this? any pointers? And finally, is this code efficient or is there a more efficient way of doing it? Many many thanks in advance.

Code:

&lt;?php /** * add user details to sub db */ defined('_JEXEC') or die('Restricted access'); ?&gt; &lt;?php class plgHikashopAdd_Sub extends JPlugin { function onAfterOrderUpdate(&amp;$order,&amp;$send_email){ if(!empty($order-&gt;order_id)){ if($order-&gt;order_status == 'confirmed'){ if(empty($order-&gt;order_product_id)){ $orderClass = hikashop::get('class.order'); $dbOrder = $orderClass-&gt;get($order-&gt;order_id); $orderClass=$orderClass-&gt;loadFullOrder($order-&gt;order_id, false, false); $fname = $orderClass-&gt;shipping_address-&gt;address_firstname; $add = $orderClass-&gt;shipping_address-&gt;address_street; $pc = $orderClass-&gt;shipping_address-&gt;address_post_code; $prod = $orderClass-&gt;order_full_price; } if(empty($orderClass-&gt;customer)){ $userClass = hikashop_get('class.user'); $orderClass-&gt;customer = $userClass-&gt;get($orderClass-&gt;order_user_id); $email = $orderClass-&gt;user_email; } $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); mysql_query("INSERT INTO subs (name, address, postcode, prod_id) VALUES ('$fname', '$add', '$pc', '$email')"); mysql_close($con); } } return true; } }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago -  15 years 1 month ago [\#26900](#26900) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26900 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

I don't know why code isn't showing above. I have attached the php file.

####  *This attachment is hidden for guests.
Please log in or register to see it.*

Last edit: 15 years 1 month ago by [spoOx](/forum/user/964-spoox "View spoOx's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

15 years 1 month ago [\#26904](#26904) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26904 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

Your code seems ok.

You should activate the display of errors in your php.ini in order to see the error message instead of a blank page.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago [\#26905](#26905) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26905 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

Hi Nicolas,

sorry for the misunderstanding. There's no blank page. The code runs fine and inserts all details in to DB except the email address. Maybe I am doing something wrong in retreiving the email address? It is not being retrieved?

Also, how can I make it so that the query only works if the order contains a product with the the product id 1, 5 or 7 ? Something like: if (order_item_id == 1 or 5 or 7) then ...

Many Thanks

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

15 years 1 month ago [\#26909](#26909) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26909 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

You have the code:
$orderClass-&gt;customer = $userClass-&gt;get($orderClass-&gt;order_user_id);

$email = $orderClass-&gt;user_email;

where it should be:
$orderClass-&gt;customer = $userClass-&gt;get($orderClass-&gt;order_user_id);

$email = $orderClass-&gt;customer-&gt;user_email;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

15 years 1 month ago [\#26910](#26910) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#26910 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

For the products, you should loop on the variable $orderClass-&gt;products and see which products are there or not...
$ok = true;
foreach($orderClass-&gt;products as $product){
if($product-&gt;prtoduct_id == 1) $ok = false;
}
if($ok){
//do something
}else{
//do something else
}

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago [\#27088](#27088) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#27088 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

Hi Nicolas,

many thanks for your replies. they have been extremely useful and I am almost done. However, 1 last problem: If the product I select has quantity of say 2 or 3, I run a for loop to add the field twice or three times in the database, however, if there is another item in the order which I don't want to select but that has a quantity of say 5 then the order is inserted in to db 5 times. For example:

Product 1 - ID = 1 - Quantity = 2 - I want to insert something in to the database 2 times but in the same order I have:
Product 2 - ID = 2 - Quantity = 5 - This is not one of the IDs I want to insert in to DB so it should only insert the record twice in DB but it does it 5 times for some reason ![:(](/media/kunena/emoticons/22.png ":(")

Below is the selected code:

foreach($orderClass-&gt;products as $product){
if($product-&gt;product_id == 1 &#124;&#124; $product-&gt;product_id == 18 &#124;&#124; $product-&gt;product_id == 42 &#124;&#124; $product-&gt;product_id == 46 &#124;&#124; $product-&gt;product_id == 22 &#124;&#124; $product-&gt;product_id == 23 &#124;&#124; $product-&gt;product_id == 43 &#124;&#124; $product-&gt;product_id == 47) $ok = true;
}
if($ok){

$qty = $product-&gt;order_product_quantity;
$notes .= " Quantity: ";
$notes .= "$qty";

for ($i=1; $i&lt;=$qty; $i++)
{
Run SQL Query here
.....
}

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago -  15 years 1 month ago [\#27090](#27090) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#27090 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

I guess it looks as if it goes through the whole order and picks out the last product in the order and gets its quantity.

Is it possible for it to loop through the order one product at a time and if the product_id matches one of the ID's then get that products quantity and run the query?

Last edit: 15 years 1 month ago by [spoOx](/forum/user/964-spoox "View spoOx's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

15 years 1 month ago [\#27092](#27092) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#27092 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

You should put your whole query code in the foreach then:

foreach($orderClass-&gt;products as $product){
$ok = false; //Product ID check
if($product-&gt;product_id == 1 &#124;&#124; $product-&gt;product_id == 18 &#124;&#124; $product-&gt;product_id == 42 &#124;&#124; $product-&gt;product_id == 46 &#124;&#124; $product-&gt;product_id == 22 &#124;&#124; $product-&gt;product_id == 23 &#124;&#124; $product-&gt;product_id == 43 &#124;&#124; $product-&gt;product_id == 47) $ok = true;

if($ok){

$qty = $product-&gt;order_product_quantity;
$notes .= " Quantity: ";
$notes .= "$qty";

$PID = $product-&gt;product_id;
$notes .= " PID: ";
$notes .= "$PID";

for ($i=1; $i&lt;=$qty; $i++)
{

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_set_charset('utf8',$con);

mysql_select_db("test", $con);

mysql_query("INSERT INTO contacts2 (&#96;First Name&#96;, &#96;Last Name&#96;, &#96;E-mail Address&#96;, &#96;Home Phone&#96;, Address, City, &#96;State/Province&#96;, &#96;Post Code&#96;, &#96;Country/Region&#96;, &#96;Date Subscribed&#96;, &#96;Subscription End Date&#96;, &#96;Notes&#96;)
VALUES ('$fname', '$lname', '$email', '$tel', '$add', '$city', '$state', '$pcode', '$country', NOW(), DATE_ADD(NOW(), INTERVAL 1 YEAR), '$notes')");

mysql_close($con);

} // end of for loop

} // end of if OK

}

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago [\#27093](#27093) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#27093 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

Hi Nicolas,

Thanks for the prompt reply but now it runs 7 times.. so 2 times for Product ID 1 and then 5 times for Product ID 2. It should only run for Product ID 1 as Product ID 2 is not included in:

if($product-&gt;product_id == 1 &#124;&#124; $product-&gt;product_id == 18 &#124;&#124; $product-&gt;product_id == 42 &#124;&#124; $product-&gt;product_id == 46 &#124;&#124; $product-&gt;product_id == 22 &#124;&#124; $product-&gt;product_id == 23 &#124;&#124; $product-&gt;product_id == 43 &#124;&#124; $product-&gt;product_id == 47)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[spoOx](/forum/user/964-spoox "View spoOx's Profile")**
- [![spoOx's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/964-spoox "View spoOx's Profile") Topic Author
- [ Offline](/forum/user/964-spoox)

Less More

- Posts: 45
- Thank you received: 0
-
-

15 years 1 month ago -  15 years 1 month ago [\#27094](#27094) by [spoOx](/forum/user/964-spoox "View spoOx's Profile")  Replied by *[spoOx](/forum/user/964-spoox "View spoOx's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#27094 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

think i've fixed it by running another if statement below:

if($PID == 1 &#124;&#124; $PID == 18 &#124;&#124; $PID == 42 &#124;&#124; $PID == 46 &#124;&#124; $PID == 22 &#124;&#124; $PID == 23 &#124;&#124; $PID == 43 &#124;&#124; $PID == 47 &#124;&#124; $PID == 3)

{
run the i loop etc
}

but is this efficient? why would it still run for product ID's not specified in the first if ?

Last edit: 15 years 1 month ago by [spoOx](/forum/user/964-spoox "View spoOx's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

15 years 1 month ago [\#27095](#27095) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Run a query after order is confirmed..](/forum/4-how-to/26786-run-a-query-after-order-is-confirmed#27095 "Hi,  I was wondering if somebody has done the following. Having read some previous posts I know it's possible. Unfortunately, my coding is not great so if somebody has done this and could kindly share their code I would highly appreciate it:  I am looking to run a mysql query after an order has been confirmed (payment received from paypal) and it contains a certain item. I would like to take the customer's details and insert them in to a seperate database.  As mentioned, I have little coding experience but any samples/exmaples should help me to get started..  Thanks in advance :)")*

If you don't want it to run several times for the same product, then you should remove your for ($i=1; $i&lt;=$qty; $i++) so that the query is only run once per product.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzI2Nzg2LXJ1bi1hLXF1ZXJ5LWFmdGVyLW9yZGVyLWlzLWNvbmZpcm1lZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.089 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
